Forum: Ruby Constructors

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6b73bf796322d53d58a5da341cea8374?d=identicon&s=25 exiquio (Guest)
on 2008-11-03 17:05
(Received via mailing list)
The following is the beginning of a Java-esque new operator.

def new o
  o.class == Class ? o.new : o
end

Used with the String class you can do:

new String # => ""
new String('foo') # => "foo"

But this is not the case with a class like Object:

new Object # okay
new Object() # error

My question is, what are classes like Array and String defining that
Object isn't? And how can I define my own? Thanks in advanced.
This topic is locked and can not be replied to.