On Fri, May 6, 2011 at 5:52 PM, Silkmoth Silkmoth <phasme / gmx.fr> wrote:
> Hi,
>
> I just want to create a subclass of Gtk::Windows and set parameters for
> the initialize method of this subclass. Here is the simple code:
>
> #!/usr/bin/ruby
> require 'gtk2'
>
> class RubyApp < Gtk::Window
>   
>  
>  
>  
>  
>  >   >  >  >  
>    >  
>  
>    
>  
>  ݬ᫱>  
>   >  
> end
>
> Gtk.init
>   
> Gtk.main
>
> If i run the script, I get this error:
> in `initialize': wrong number of arguments (2 for 1) (ArgumentError)
>
> I try a lot of things and after a lot of research on the net, I can't
> find the solution or the tricks that should solve the problem.
>
> Have you got any idea why I can't define new parameters for the
> initialize method.
>
> Thanks
>
> --
> Posted via http://www.ruby-forum.com/.
>
>

If I'm not mistaken, you are using this library:

http://ruby-gnome2.sourceforge.jp

When you call super without params, it calls the same method you are
in (in this case initialize), with the same params you received. So
you are calling the Gtk::Window#initialize passing the two parameters
you passed to your initialize method. As you can see, Gtk::Window
doesn't override initialize, it inherits the method from a parent
class. From the error message, you see it's expecting only one
parameter (from the method Gtk::Window.new we might think that the
parameter is the window type), and you are passing two, hence the
error. You can do like this:


class RubyApp < Gtk::Window
  def initialize( a , b)
    super() # I think the parameter is optional, looking at the
Gtk::Window.new documentation
    ...


Hope this helps,

Jesus.