Hi,
In message "[ruby-talk:00632] Re: Next misbehavior (sorry :-)"
on 99/08/11, clemens.hintze / alcatel.de <clemens.hintze / alcatel.de> writes:
>> class MyString<String
>> class << self
>> def new(*args)
>> res = super(args[0] || "")
>> res.instance_eval{ initialize(*args) }
>> res
>> end
>> end
>>
>
>Can you explain me, please, why do you do it that way? I have done it
>as following:
>
> class MyString<String
> def MyString.new(*args)
> res=super(args[0] || "")
> res.instance_eval{ initialize *args }
> res
> end
> end
>
>It seems to work. Is there any advantage using the `class << whatever'
>style here? :-/
Well, they are simply different in their styles.
No advantage lives in my above example.
I think there some merits exists in `class << whatever' style.
- Scope is easy to see.
- A private class method can be call.
- Less keyboard typing if several class methods are defined :-)
-- gotoken