Invisible methods and inheritance

L

Leslie Viljoen

Hello!

Does anyone know the reason for the following?

p rio('.').all.dirs.methods.include?("each")
p rio('.').all.dirs.methods.respond_to?("each")
false
true


I can call dirs.each, but I am trying to trace which .each method is
called in the rio source. Also how can I find the parent/superclass
class of a class? (ie. something like Array.parent?)

Les


--=20
If you could create a machine that copies hamburgers =97 you put one
hamburger in and two equally good hamburgers come out the other side =97
it would be unethical not to do so and make it freely available.
 
R

Ryan Davis

Hello!

Does anyone know the reason for the following?

p rio('.').all.dirs.methods.include?("each")
p rio('.').all.dirs.methods.respond_to?("each")

I think you meant:

p rio('.').all.dirs.respond_to?("each")

you don't want to ask the result of methods if IT responds to each,
you want to ask the result of dirs.
I can call dirs.each, but I am trying to trace which .each method is
called in the rio source.

Don't forget that things like method_missing (and even respond_to?)
can be overridden.
Also how can I find the parent/superclass
class of a class? (ie. something like Array.parent?)
=> Object

Remember, ri is your friend, just ask it what you asked us and you'll
often find your answer:

% ri superclass
------------------------------------------------------- Class#superclass
class.superclass -> a_super_class or nil
------------------------------------------------------------------------
Returns the superclass of _class_, or +nil+.

File.superclass #=> IO
IO.superclass #=> Object
Object.superclass #=> nil
 
L

Leslie Viljoen

I think you meant:

p rio('.').all.dirs.respond_to?("each")

you don't want to ask the result of methods if IT responds to each,
you want to ask the result of dirs.


Don't forget that things like method_missing (and even respond_to?)
can be overridden.

=3D> Object

Remember, ri is your friend, just ask it what you asked us and you'll
often find your answer:

% ri superclass
------------------------------------------------------- Class#superclass
class.superclass -> a_super_class or nil
------------------------------------------------------------------------
Returns the superclass of _class_, or +nil+.

File.superclass #=3D> IO
IO.superclass #=3D> Object
Object.superclass #=3D> nil


Thanks Ryan. It seems I am much more tired than I thought I was ;-)


--=20
If you could create a machine that copies hamburgers =97 you put one
hamburger in and two equally good hamburgers come out the other side =97
it would be unethical not to do so and make it freely available.
 

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,773
Messages
2,569,594
Members
45,125
Latest member
VinayKumar Nevatia_
Top