From: "ToMaTo@..." Date: 2012-03-07T02:10:45+09:00 Subject: Re: Getting the class of an object. --bcaec553ff0c72edfd04ba961fcf Content-Type: text/plain; charset=UTF-8 Are you talking about sth. like this: b.method(:foo).owner #=> Dance b.method(:bar).owner #=> Boogy ? On Tue, Mar 6, 2012 at 11:34 AM, Ralph Shnelvar wrote: > 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 > > > -- Best wishes, Jie Fan Life is a miracle. --bcaec553ff0c72edfd04ba961fcf Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Are you talking about sth. like this:

b.method(:foo).own= er #=3D> Dance
b.method(:bar).owner #=3D> Boogy
<= br>
?

On Tue, Mar 6, 201= 2 at 11:34 AM, Ralph Shnelvar <ralphs@dos32.com> wrote:
Consider;

- - -

class Dance
=C2=A0 =C2=A0def foo
=C2=A0 =C2=A0 =C2=A0 =C2=A0puts "foo is executed"
=C2=A0 =C2=A0 =C2=A0 =C2=A042
=C2=A0 =C2=A0end
end

class Boogy < Dance
=C2=A0 =C2=A0def bar
=C2=A0 =C2=A0 =C2=A0 =C2=A0puts (foo.class)
=C2=A0 =C2=A0end
end

b =3D Boogy.new

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

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

- - -

Let's focus on the line
=C2=A0puts (foo.class)

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

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

So I
=C2=A0puts (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) a= nd 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





--
Best wishes,<= /div>
Jie Fan
=C2=A0
Life is a miracle.

--bcaec553ff0c72edfd04ba961fcf--