In Python we can "dir" a module, like this:
>>> import re
>>> dir(re)
And it lists all functions in the module. Is there a similar way to do this in Ruby?
In Python we can "dir" a module, like this:
>>> import re
>>> dir(re)
And it lists all functions in the module. Is there a similar way to do this in Ruby?
I'd go for something like this:
Which will give you a yaml representation of the sorted array of methods. Note that this can be used to list the methods of both classes and objects.
I would have made this a comment to jonelf's answer, but apparently I don't have enough rep.
some_object.methods.sort - Object.new.methods
This isn't exactly what you were asking as others have said, but it gives you the info you are after.
I like to have this in my .irbrc:
So when I'm in irb:
Or even cuter - with grep:
As far as I know not exactly but you get somewhere with
Not really. Like the others said, you can get part of what you want by listing class instance methods (e.g.
String.instance_methods
) but that doesn't help you if a file you open reopens a class (unless you check before and after).If you don't need programmatic access to the list of methods, consider checking out the documentation for a class, module or method using the
ri
command line tool.Tip for "searching" for a method in irb:
Tip for trying out methods on a value for comparison:
Also, note that you won't get all the same information as Python's dir with object.methods. You have to use a combination of object.methods and class.constants, also class.singleton_methods to get the class methods.