Browsing documentation in Pry is easy with the show-doc
command. If you every want to look a methods documentation while working on your code, show-doc will save you time.
Running the -h
or --help
option on the show-doc command will give you a basic over view of the different options and examples.
[1] pry(main)> show-doc -h
You can view the documentation of a class or method by simple running:
[1] pry(main)> show-doc MethodName
or by using the short-hand version of show-doc:
[1] pry(main)> ? MethodName
Finding documentation on the flatten
method of an array.
[1] pry(main)> cd Array
[2] pry(Array):1> ? flatten
From: array.c (C Method):
Owner: Array
Visibility: public
Signature: flatten(*arg1)
Number of lines: 15
Returns a new array that is a one-dimensional flattening of self
(recursively).
That is, for every element that is an array, extract its elements into
the new array.
The optional level argument determines the level of recursion to
flatten.
s = [ 1, 2, 3 ] #=> [1, 2, 3]
t = [ 4, 5, 6, [7, 8] ] #=> [4, 5, 6, [7, 8]]
a = [ s, t, 9, 10 ] #=> [[1, 2, 3], [4, 5, 6, [7, 8]], 9, 10]
a.flatten #=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
a = [ 1, 2, [3, [4, 5] ] ]
a.flatten(1) #=> [1, 2, 3, [4, 5]]
You can also get the same results without switching the directory.
[5] pry(main)> ? Array#flatten
If you forgot what parameters your defined method takes or even what your method dose. You could run the show-docs
command on your method and it will return with any comments and information about your method.
[1] pry(main)> load 'encryptor.rb'
Enter your password: *******
You are now logged in!
=> true
[2] pry(main)> ? Encryptor#encrypt
From: encryptor.rb @ line 38:
Owner: Encryptor
Visibility: public
Signature: encrypt(string=?, rotation=?)
Number of lines: 1
Takes the input and splits it into an array then passes it to the encrypt_letters method.
From that I can see what line the method is at, that it takes two arguments and a description of what the method dose.
By using show-doc
you can find a lot of great information just by looking through the documentation of different methods. It also provides a quick way to find the information you need with out having to leave your terminal/iTerm window.