When I go into irb and type in a command that does not exist I get an error stating
"undefined local variable or method 'my_method' for main:Object (NameError)"
Is there a way to just get a list of what local variables or methods ARE available? This would be really useful for exploring ruby.
To find out instance variables, you can use
Kernel#instance_variables
as Zabba pointed out.For methods available on an object, I use
my_object.methods - Object.methods
to find out what non-obvious methods are available to my object. This narrows down the list and is considerably easy to read.Great answers.
As you explore, you have these at your disposal:
and
Usage like :
Can make review easier too.
Some special cases exist like
... will give you only the instance methods defined in the String class, omitting the classes it inherited from any ancestors. As I expect you know, you can see more here: http://www.ruby-doc.org/docs/ProgrammingRuby/ but it's not as fun as inspecting and reflecting in irb.
Happy exploring -
Perry
Look for methods in the Kernel, Object and Module : e.g. local_variables, instance_methods, instance_variables.
Other great methods in there. inspect is another one.