Forum: Ruby get methods from module

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.
97334b75c93574ed3e514f33849f0953?d=identicon&s=25 Mario Ruiz (tcblues)
on 2016-09-28 14:30
I have something like this
module MyModule1
  module MyModule2
    def self.method1
    end
    def self.method2
    end
  end
end

I need to get the methods declared inside MyModule2 and I need the self.
to be able to access it like MyModule1::MyModule2.method1

If i try to get them like this:
MyModule1::MyModule2.instance_methods

nothing is captured but if i remove the self. yes I get the methods but
I need to use the self.
0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2016-09-29 11:28
You didn't define any instance methods. You will find your two methods
if you do a

    MyModule1::MyModule2::methods
97334b75c93574ed3e514f33849f0953?d=identicon&s=25 Mario Ruiz (tcblues)
on 2016-10-12 11:40
by doing that i get all methods not only the ones I created
Cc704ce316e72af824ccd38cfa53104b?d=identicon&s=25 Raja Gopalan (arc)
on 2016-10-14 12:52
puts MyModule1::MyModule2::methods(false)

#method1
#method2
97334b75c93574ed3e514f33849f0953?d=identicon&s=25 Mario Ruiz (tcblues)
on 2016-10-18 13:52
Thanks a lot!!!!
0fa73332c8e4a3b06ea439fd3f034322?d=identicon&s=25 Ronald Fischer (rovf)
on 2016-11-07 09:26
Ruby has no way to track "who" wrote the code to define a method : The
definition of a method can occur while executing or requiring something
from the Ruby stdlib, or some Gem, or some Code you wrote, and this type
of authorship is hard (maybe impossible) to track.

You can track all new methods added after a certain time in program
execution, by recording first a list of all methods, and later - when
you want to know the changes -, recalculate the list of methods and
output the difference. As a side effect, you also would get the methods
which have been removed from an object (a rare, but possible case).
This topic is locked and can not be replied to.