Forum: Ruby Constructors

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
exiquio (Guest)
on 2008-11-03 18:05
(Received via mailing list)
The following is the beginning of a Java-esque new operator.

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

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.