small medium large xlarge

Generic-user-small
16 Feb 2010, 19:31
Frank (9 posts)

I’m currently working my way through the Eigenclasses chapter.

On page 144 there’s a line of code:

obj.eigenclass.superclass # => D

On Ruby 1.9.1 I don’t actually get ‘D’ as the result for that line of code. Instead I get # However, I do get 'D' if I do:

obj.class

I’m missing something here or misunderstanding something. What is # and how does it differ from 'D'?

Photo_17_pragsmall
26 Feb 2010, 16:43
Paolo Perrotta (51 posts)

Hi, Frank. Sorry for the very late reply.

I tried this in Ruby 1.9.1p376:

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

class C; end
class D < C; end

obj = D.new
obj.eigenclass.superclass # => D

This tends to be an area where some versions of Ruby had bugs and regression. Maybe you can try it with the very latest Ruby 1.9?