how can I view all the available methods on an object in ruby. I'm using the aptana IDE when I type File. no methods are displayed. I'm coming from an eclipse/java background.
Thanks
Ruby doesn't really have functions. Rather, it has two slightly different concepts - methods and Procs (which are, as we have seen, simply what other languages call function objects, or functors). Both are blocks of code - methods are bound to Objects, and Procs are bound to the local variables in scope.
respond_to is a Rails method for responding to particular request types. For example: def index @people = Person.find(:all) respond_to do |format| format.html format.xml { render :xml => @people.to_xml } end end.
There are two standard approaches for defining class method in Ruby. The first one is the “def self. method” (let's call it Style #1), and the second one is the “class << self” (let's call it Style #2). Both of them have pros and cons.
There are several methods:
obj.methods
obj.public_methods
obj.private_methods
obj.protected_methods
obj.singleton_methods
Update
To get the object methods apart from all inherited methods you can do:
obj.methods(false)
As Tempus mentioned in the comments, the following command is very helpful to get the current object methods apart from the Object(base class) inherited methods:
obj.methods - Object.methods
You can pass true
to the methods if you want to ignore the methods defined in superclasses:
obj.methods(true)
obj.public_methods(true)
obj.private_methods(true)
obj.protected_methods(true)
obj.singleton_methods(true)
Or, if you only want to remove the most common methods that are defined in the Object
class, you want to append either - Object.methods
or - Object.instance_methods
, depending on whether obj
is a class or an instance of a class.
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