|
From: Kouhei S. <ko...@co...> - 2016-11-09 14:24:59
|
Hi,
In <0ab...@gm...>
"Re: [ruby-gnome2-devel-en] Gtk::TreeViewColumn initialization with area not possible" on Wed, 9 Nov 2016 11:57:47 +0100,
cedlemo <ce...@gm...> wrote:
> We could use this trick
>
> irb(main):001:0> def myfn(*args)
> irb(main):002:1> puts args.size
> irb(main):003:1> end
> => :myfn
> irb(main):004:0> myfn("arg1","arg2","arg3")
> 3
> => nil
> irb(main):005:0> myfn(:arg1 => "arg1", :arg2 => "arg3")
> 1
> => nil
>
> If args size is equal to one then you use your code else you use the
> previous code. This way allows us to implement the has form while
> we keep the compatibility with the previous code. We have done done this
> already in some of the ruby-gnome class but Kou would offer you
> a better answer than me.
I like cedlemo's approach.
def initialize(*args)
if args.size == 1 and args[0].is_a?(Hash)
options = args[0]
area = options[:area]
renderer = options[:renderer]
title = options[:title]
attributes = options[:attributes]
else
area, renderer, attributes = args
end
attributes ||= {}
# ...
end
Thanks,
--
kou
|