2

This method is to return eigenclass of any object:

class Object
  def eigenclass
    class << self; self; end
  end
end

Example for String:

"abc".eigenclass # => #<Class:#<String:0x331df0>>

Array:

[1, 2].eigenclass # => #<Class:#<Array:0x0000000065d218>>

But with Fixnum:

1.eigenclass # => TypeError: can't define singleton

Why?

eugene
  • 550
  • 4
  • 15
  • I think [this](http://stackoverflow.com/questions/13962147/why-cant-singleton-methods-be-defined-on-symbols-or-fixnums) might help you. Please go through it. – sreeraj nyros Oct 06 '16 at 04:12

1 Answers1

1

As the Ruby Docs say:

There is effectively only one Fixnum object instance for any given integer value, so, for example, you cannot add a singleton method to a Fixnum.

The same is true for Bignum, Float and Symbol

Santosh Sharma
  • 2,114
  • 1
  • 17
  • 28