ruby -e 'puts .methods.sort' |
while read name ; do
echo == $name
ri Array."${name}" | cat
done
Interestingly, a lot of methods didn't return anything via ri. For example:
$ ri Array.methods
Nothing known about Array.methods
Anyone have any suggestions on a "cleaner" way to discover methods and
their docs?
The first two things that come to mind are: www.ruby-doc.org, if you want online doc, or one of the many fine books about Ruby if you want dead-tree doc.
C:\Documents and Settings\gavin.kistner>qri methods
------------------------------------------------------ Multiple
choices:
Kernel#methods, Object#methods
C:\Documents and Settings\gavin.kistner>qri Object.methods
···
On Dec 19, 5:11 pm, Robert Citek <robert.ci...@gmail.com> wrote:
Discovered this with a brute-force search:
ruby -e 'puts .methods.sort' |
while read name ; do
echo == $name
ri Array."${name}" | cat
done
Interestingly, a lot of methods didn't return anything via ri. For example:
$ ri Array.methods
Nothing known about Array.methods
---------------------------------------------------------
Object#methods
obj.methods => array
------------------------------------------------------------------------
Returns a list of the names of methods publicly accessible in
_obj_. This will include all the methods accessible in _obj_'s
ancestors.
class Klass
def kMethod()
end
end
k = Klass.new
k.methods[0..9] #=> ["kMethod", "freeze", "nil?", "is_a?",
"class", "instance_variable_set",
"methods", "extend", "<em>send</em>",
"instance_eval"]
k.methods.length #=> 42
But yes - documentation helps you find out what methods are available.
First, thank you for the example. Made me wonder about the .to_a
method and discover that 1..10 works differently in ruby than in perl:
$ perl -le 'print 1..10'
12345678910
$ ruby -le 'print 1..10'
1..10
To answer your question: because 'echo $(seq 1 10)' represents the
abstract "any delimited input data" model, which could be multi-line,
thus the -lane options. Also, because I tend to build up my
quick-and-dirty scripts from the command line: first head the file,
then filter/modify the data stream, repeat quickly. So the example
above is merely one in a series of commands: