Class ExistingName

Recently i created a file object.rb

class Object

I forgot that ruby already reserved this name, so I renamed the class.

But I was still curious. Is there a way to use a "class Object"?

I guess there is no easy way, many things would have to be renamed.

Still, I write this here because perhaps one of you has some idea.

···

--
Posted via http://www.ruby-forum.com/.

Marc Heiler wrote:

Recently i created a file object.rb

class Object

I forgot that ruby already reserved this name, so I renamed the class.

But I was still curious. Is there a way to use a "class Object"?

I guess there is no easy way, many things would have to be renamed.

Still, I write this here because perhaps one of you has some idea.

You could place it inside a module:

···

-----------------------------------
module A

  class Object

    def foo
      "foo"
    end

  end

end

obj = A::Object.new
p obj.foo #=> foo
obj = Object.new
p obj.foo #=> NoMethodError
-----------------------------------
Even if you include it, Object isn't overwritten:

include A

obj = Object.new
p obj.foo #=> NoMethodError
-----------------------------------

Marvin
--
Posted via http://www.ruby-forum.com/\.

You could place it inside a module:

Thanks that helped.

···

--
Posted via http://www.ruby-forum.com/\.