I wonder how one can list all methods in a module, but not including inherited methods.
eg.
module Software
def exit
puts "exited"
end
end
puts Software.methods
Will list not only exit, but all inherited methods.
Is is possible to just list exit?
Thanks
You can use dir(module) to see all available methods/attributes.
We can list down all the functions present in a Python module by simply using the dir() method in the Python shell or in the command prompt shell.
There is the dir(theobject) method to list all the fields and methods of your object (as a tuple) and the inspect module (as codeape write) to list the fields and methods with their doc (in """). Because everything (even fields) might be called in Python, I'm not sure there is a built-in function to list only methods.
Python – all() function The Python all() function returns true if all the elements of a given iterable (List, Dictionary, Tuple, set, etc.)
Actually Software.methods
will not list exit
. Software.instance_methods
will list exit
as well as any inherited methods (which in this case is nothing because modules don't inherit any methods unless you include another module). Software.instance_methods(false)
will only list methods defined in Software
.
Software.public_instance_methods
seems to work for your example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With