Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Ruby
How do you know what class defines method foo()?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Sam Kong, post: 4498093"] Hi, folks! What's the easiest(simplest) code to find a class/module that first defines a specific method? I became curious while I was looking for a document of Array#partition method. Actually the method is defined in Enumerable module. But I couldn't guess that it was defined there until I checked Array class's doc first. If the inheritance(or mixin) hierarchy is very complex, it will take long to find a method. The one I can think of is using MyClass.ancestors and MyClass.instance_methods recursively (or repeatedly). Is there a better way? (On my second thought, singleton classes should also be considered, right?) The method prototype might be like... #returns a class or module which defines the method def defined_where(obj, method_name) ... end Thanks. Sam [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Ruby
How do you know what class defines method foo()?
Top