In message "[ruby-talk:9688] new and initialize -"
on 01/01/22, "g forever" <g24ever / hotmail.com> writes:
>I am not suggesting a change but I am curious why languages including Ruby
>do not use new as a class method
Simple reason: there isn't an instance before that is created by `new'.
>e.g.
>class Test
>etc.
>def new(x)
>@z= x;
>end
>
>etc.
>end
>
>mytest= Test.new
>
>
>instead of 'initalize'
>
>Is there some fundamental reason why the latter is the way to do it.
As you wrote, `new' is sent to Test class (Test.new), but not Test
object (aTest.new).
Btw, every Ruby's method invocation can be written by send like,
reciever.send(symbol, *args)
e.g.,
t = Test.send(:new, "foo")
t.send(:z)
-- Gotoken