One thing I have often wondered is why the ruby constructor isn’t called
new?
In my laziness I would rather type new than initialize.
It seems clearer than initialize, and appears to work just fine.
Perhaps both could be supported?
What thoughts?
Ralph
class Foo
def new
puts "Foo.new"
end
def Foo.new
x=super
x.new
x
end
def bar
puts "Foo:bar"
end
end
Foo.new().bar
— Ralph Mason ralph.mason@telogis.com wrote:
One thing I have often wondered is why the ruby constructor isn’t called
new?
In my laziness I would rather type new than initialize.
Set it up as an alias :new etc…???
– Thomas Adam
···
=====
“The Linux Weekend Mechanic” – http://linuxgazette.net
“TAG Editor” – http://linuxgazette.net
“ We’ll just save up your sins, Thomas, and punish
you for all of them at once when you get better. The
experience will probably kill you. :)”
– Benjamin A. Okopnik (Linux Gazette Technical Editor)
Yahoo! Messenger - Communicate instantly…“Ping”
your friends today! Download Messenger Now
http://uk.messenger.yahoo.com/download/index.html
Gennady1
(Gennady)
14 January 2004 23:00
3
Ralph Mason wrote:
One thing I have often wondered is why the ruby constructor isn’t called
new?
In my laziness I would rather type new than initialize.
It seems clearer than initialize, and appears to work just fine.
Perhaps both could be supported?
What thoughts?
Ralph
class Foo
def new
puts “Foo.new”
end
def Foo.new
x=super
x.new
x
end
def bar
puts “Foo:bar”
end
end
Foo.new().bar
Search ruby-talk archives at
http://www.ruby-talk.org/ruby/ruby-talk/index.shtml
for many discussions on the issue.
Gennady.
FWIW, in vim, I use !init and it types
def initialize()
end
This works for me.
-austin
···
On Thu, 15 Jan 2004 07:49:26 +0900, Ralph Mason wrote:
One thing I have often wondered is why the ruby constructor isn’t called
new?
In my laziness I would rather type new than initialize.
It seems clearer than initialize, and appears to work just fine. Perhaps
both could be supported?
–
austin ziegler * austin@halostatue.ca * Toronto, ON, Canada
software designer * pragmatic programmer * 2004.01.14
* 22.46.06
Robert
(Robert)
15 January 2004 09:26
5
“Ralph Mason” ralph.mason@telogis.com schrieb im Newsbeitrag
news:4005C74A.7040304@telogis.com …
One thing I have often wondered is why the ruby constructor isn’t called
new?
Maybe because there are two things involved in object construction and
different names make this clearer: first an instance is allocated and
then it is initialized . At the point in time when initialize is run,
the memory is already allocated.
Regards
robert
In my laziness I would rather type new than initialize.
It seems clearer than initialize, and appears to work just fine.
Perhaps both could be supported?
You can do
class Foo
def i(bar, baz)
@bar , @baz = bar, baz
self
end
end
f = Foo.new.i(“how’s”, “that?”)
Regards
robert