Consider;

- - -

class Dance
    def foo
        puts "foo is executed"
        42
    end
end

class Boogy < Dance
    def bar
        puts (foo.class)
    end
end

b = Boogy.new

b.foo # prints "foo is executed" ... expected.

b.bar # prints "foo is executed\nFixnum" ... not expected!

- - -

Let's focus on the line
  puts (foo.class)

So let's say I'm in the middle of a debugging session trying to debug the bar method.

I see this thing called "foo" and I want to know what it is.

So I
  puts (foo.class)

Since everything in ruby is an object and all objects have classes, I'm expecting to print out the class of this thing called foo.

What happens, though is that foo gets executed (which is not what I want) and returns 42 ... whose class is Fixnum.


Questions:
How can I tell what class of object foo is without executing it?
Is there a class called "Method" in the Ruby class hierarchy?
What class of object does define_method return?


Ralph Shnelvar