Forum: Ruby Invisible methods and inheritance

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
37ee5fa90f5eaeef62553629382497f7?d=identicon&s=25 Leslie Viljoen (Guest)
on 2007-04-14 00:43
(Received via mailing list)
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
5a837592409354297424994e8d62f722?d=identicon&s=25 Ryan Davis (Guest)
on 2007-04-14 00:50
(Received via mailing list)
On Apr 13, 2007, at 15:42 , Leslie Viljoen wrote:

> 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 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?)

 >> Array.superclass
=> 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
37ee5fa90f5eaeef62553629382497f7?d=identicon&s=25 Leslie Viljoen (Guest)
on 2007-04-14 01:32
(Received via mailing list)
On 4/14/07, Ryan Davis <ryand-ruby@zenspider.com> wrote:
> >> false
> > called in the rio source.
> Remember, ri is your friend, just ask it what you asked us and you'll
>          Object.superclass   #=> nil
>


Thanks Ryan. It seems I am much more tired than I thought I was ;-)
This topic is locked and can not be replied to.