Robert Klemme
1/30/2005 2:33:00 PM
"Jeff Davis" <jdavis-list@empires.org> schrieb im Newsbeitrag
news:41FC41A1.6060304@empires.org...
>E S wrote:
>
>>Jeff Davis wrote:
>>
>>
>>>I am learning Ruby and one thing I sometimes find difficult is knowing
>>>what methods, constants, and classes are available in a given context.
>>>
>>>One example was I required a module, but I didn't know everything that
>>>the module contained. Is there a way to know everything that you can call
>>>in a given context? All the symbols that are available?
>>>
>>
>>If you want to know what a unit contains, www.ruby-doc.org is a good
>>resource (or you can use ri, or line completion in irb). If you want your
>>*code* to know what's available, try these:
>>
>>Object#instance_variables
>>Object#private_methods
>>Object#protected_methods
>>Object#public_methods
>>Object#singleton_methods
>>Module#constants
>>Module#instance_methods
>>Module#private_instance_methods
>>Module#protected_instance_methods
>>Module#public_instance_methods
>>Kernel#global_variables
>>Kernel#local_variables
>>
>>
>>
> Thanks, that's exactly what I was looking for. And thanks for the help on
> the other question also.
I use IRB a lot with this shell alias:
irb is aliased to `irb -r irb/completion'
That way you can hit tab with an instance and get all available methods:
$ irb
irb(main):001:0> a=%w{a bc d}
=> ["a", "bc", "d"]
irb(main):002:0> a.
Display all 107 possibilities? (y or n)
a.each_index a.indices
a.nitems a.size
a.__id__ a.each_with_index a.inject
a.object_id a.slice
a.__send__ a.empty? a.insert
a.pack a.slice!
a.all? a.entries a.inspect
a.partition a.sort
a.any? a.eql? a.instance_eval
a.pop a.sort!
a.assoc a.equal? a.instance_of?
a.private_methods a.sort_by
a.at a.extend a.instance_variable_get
a.protected_methods a.taint
a.class a.fetch a.instance_variable_set
a.public_methods a.tainted?
a.clear a.fill a.instance_variables
a.push a.to_a
a.clone a.find a.is_a?
a.rassoc a.to_ary
a.collect a.find_all a.join
a.reject a.to_s
a.collect! a.first a.kind_of?
a.reject! a.transpose
a.compact a.flatten a.last
a.replace a.type
a.compact! a.flatten! a.length
a.respond_to? a.uniq
a.concat a.freeze a.map
a.reverse a.uniq!
a.delete a.frozen? a.map!
a.reverse! a.unshift
a.delete_at a.grep a.max
a.reverse_each a.untaint
a.delete_if a.hash a.member?
a.rindex a.values_at
a.detect a.id a.method
a.select a.zip
a.display a.include? a.methods
a.send
a.dup a.index a.min
a.shift
a.each a.indexes a.nil?
a.singleton_methods
irb(main):002:0> a.
Kind regards
robert