How do I tell the difference between a class C and the singletonclass of an instance of C

D

deanwampler

Note: parts of this message were removed by the gateway to make it a legal Usenet post.

I just figured out a way, if I also have the instance "c".

c.instance_of?(C) # => true
c.instance_of?(sing) # => false

Also works for kind_of? and is_a?

Thanks, Dean! ;)

Suppose that:

class C; end
c = C.new
sing = (class << c; self; end)

If a method is called with C and sing, but I don't know which is first and
which is second in the parameter list, how do I tell them apart?

Thanks,
dean

--
Dean Wampler
http://www.objectmentor.com
http://www.aspectprogramming.com
http://aquarium.rubyforge.org
http://www.contract4j.org




--
Dean Wampler
http://www.objectmentor.com
http://www.aspectprogramming.com
http://aquarium.rubyforge.org
http://www.contract4j.org
 
Y

ysantoso-rubytalk

Dean Wampler said:
Suppose that:

class C; end
c = C.new
sing = (class << c; self; end)

If a method is called with C and sing, but I don't know which is first and
which is second in the parameter list, how do I tell them apart?

C.name ==> "C"
sing.name ==> ""

YS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top