[Kde-bindings] qtruby: initialize should be initialize(*args)

Richard Dale Richard_Dale at tipitina.demon.co.uk
Thu Apr 14 08:33:32 UTC 2005


On Thursday 14 April 2005 09:29, jm wrote:
> In the examples you have, to use dclock.rb's DigitalClock,
>
>    def initialize
>       super
>      .
>      .
>      .
>    end
>
>   I think this should be
>
>    def initialize(*args)
>       super(*args)
>     .
>     .
>     .
>    end
>
> While what you have works the second form allows re-use especially when
> it's not the main widget. This hit me when I tried exactly that. I
> won't say how long it took for me to work this out as it is
> embarrassingly long as I naturally thought the mistake was in my code.
Yes, although 'super' by itself is equivalent to 'super(*args)' - it just 
calls super with any args passed. 

    def initialize(*args)
       super
     .
    end

I had a look at the original C++ dclock code, and it has a constructor like 
this:

    DigitalClock( QWidget *parent=0, const char *name=0 );

So the nearest equivalent code in ruby would use default parameter values:

    def initialize(parent = nil, name = nil)
       super(parent, name)
     .
     .
    end

So perhaps the dclock example should be changed to that.

-- Richard



More information about the Kde-bindings mailing list