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 forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs