pry 0.6.7pre4 → 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +83 -75
- data/README.markdown +312 -309
- data/Rakefile +103 -103
- data/bin/pry +82 -82
- data/lib/pry.rb +32 -32
- data/lib/pry/commands.rb +577 -577
- data/lib/pry/print.rb +19 -19
- data/lib/pry/prompts.rb +26 -26
- data/lib/pry/pry_class.rb +186 -186
- data/lib/pry/pry_instance.rb +316 -316
- data/lib/pry/version.rb +3 -3
- metadata +13 -13
data/CHANGELOG
CHANGED
@@ -1,75 +1,83 @@
|
|
1
|
-
|
2
|
-
*
|
3
|
-
*
|
4
|
-
|
5
|
-
|
6
|
-
*
|
7
|
-
*
|
8
|
-
|
9
|
-
|
10
|
-
*
|
11
|
-
*
|
12
|
-
|
13
|
-
|
14
|
-
*
|
15
|
-
*
|
16
|
-
|
17
|
-
|
18
|
-
*
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
* Added
|
23
|
-
*
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
*
|
31
|
-
*
|
32
|
-
*
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
*
|
37
|
-
*
|
38
|
-
*
|
39
|
-
*
|
40
|
-
*
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
*
|
47
|
-
|
48
|
-
*
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
*
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
*
|
61
|
-
|
62
|
-
|
63
|
-
*
|
64
|
-
|
65
|
-
|
66
|
-
* added
|
67
|
-
|
68
|
-
*
|
69
|
-
|
70
|
-
*
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
*
|
75
|
-
|
1
|
+
4/3/2011 version 0.6.7
|
2
|
+
* color support
|
3
|
+
* --simple-prompt for pry commandline
|
4
|
+
* -I mode for pry commandline
|
5
|
+
* --color mode for pry commandline
|
6
|
+
* clean up requires (put them all in one place)
|
7
|
+
* simple-prompt command and toggle-color commandd.
|
8
|
+
|
9
|
+
28/2/2011 version 0.6.3
|
10
|
+
* Using MethodSource 0.3.4 so 1.8 show-method support provided
|
11
|
+
* `Set` class added to list of classes that are inspected
|
12
|
+
|
13
|
+
26/2/2011 version 0.6.1
|
14
|
+
* !@ command alias for exit_all
|
15
|
+
* `cd /` for breaking out to pry top level (jump-to 0)
|
16
|
+
* made `-e` option work in a more effective way for `pry` command line invocation
|
17
|
+
* exit and exit-all commands now accept a parameter, this parameter becomes the return value of repl()
|
18
|
+
* `command` method from CommandBase now accepts a :keep_retval arg that determines if command value is returned to pry session or just `nil` (`nil` was old behaviour)
|
19
|
+
* tests for new :keep_retval and exit-all/exit behaviour; :keep_retval will remain undocumented.
|
20
|
+
|
21
|
+
22/2/2011 version 0.5.8
|
22
|
+
* Added -c (context) option to show-doc, show-methods and eval-file
|
23
|
+
* Fixed up ordering issue of -c and -r parameters to command line pry
|
24
|
+
|
25
|
+
21/2/2011 version 0.5.7
|
26
|
+
* Added pry executable, auto-loads .pryrc in user's home directory, if it
|
27
|
+
exists.
|
28
|
+
|
29
|
+
19/2/2011 version 0.5.5
|
30
|
+
* Added Pry.run_command
|
31
|
+
* More useful error messages
|
32
|
+
* Easter eggs (game and cohen-poem)
|
33
|
+
|
34
|
+
17/2/2011 version 0.5.0
|
35
|
+
* Use clipped version of Pry.view() for large objects
|
36
|
+
* Exit Pry session on ^d
|
37
|
+
* Use Shellwords for breaking up parameters to pry commands
|
38
|
+
* Use OptionParser to parse options for default pry commands
|
39
|
+
* Add version command
|
40
|
+
* Refactor 'status' command: add current method info
|
41
|
+
* Add meth_name_from_binding utility lambda to commands.rb
|
42
|
+
* Add -M, -m, -v(erbose), -a(ll), -s(uper), -l(ocals), -i(ivars), -k(klass
|
43
|
+
vars), etc options to ls
|
44
|
+
* add -M(instance method) options to show-method and show-doc
|
45
|
+
* add --help option to most commands
|
46
|
+
* Get rid of ls_method and ls_imethods (subsumed by more powerful ls)
|
47
|
+
* Get rid of show_idoc and show_imethod
|
48
|
+
* Add special eval-file command that evals target file in current context
|
49
|
+
|
50
|
+
27/1/2011 version 0.4.5
|
51
|
+
* fixed show_method (though fragile as it references __binding_impl__
|
52
|
+
directly, making a name change to that method difficult
|
53
|
+
27/1/2011 version 0.4.4
|
54
|
+
* oops, added examples/ directory
|
55
|
+
26/1/2011 version 0.4.3
|
56
|
+
* added alias_command and desc methods to Pry::CommandBase
|
57
|
+
* changed behaviour of ls_methods and ls_imethods to return sorted lists
|
58
|
+
of methods
|
59
|
+
23/1/2011 version 0.4.1
|
60
|
+
* made it so a 'def meth;end' in an object Pry session defines singleton
|
61
|
+
methods, not methods on the class (except in the case of
|
62
|
+
immediates)
|
63
|
+
* reorganized documentation, moving customization to a separate wiki file
|
64
|
+
* storing wiki in a nested git repo, as github wiki pages have their own
|
65
|
+
repo
|
66
|
+
* added more tests for new method definition behaviour
|
67
|
+
21/1/2011 version 0.4.0
|
68
|
+
* added command API
|
69
|
+
* added many new commands, i.e ls_methods and friends
|
70
|
+
* modified other commands
|
71
|
+
* now accepts greater customization, can modify: input, output, hooks,
|
72
|
+
prompt, print object
|
73
|
+
* added tab completion (even completes commands)
|
74
|
+
* added extensive tests
|
75
|
+
* added examples
|
76
|
+
* many more changes
|
77
|
+
9/12/2010 version 0.1.3
|
78
|
+
* Got rid of rubygems dependency, refactored some code.
|
79
|
+
8/12/2010 version 0.1.2
|
80
|
+
* now rescuing SyntaxError as well as Racc::Parser error in valid_expression?
|
81
|
+
8/12/2010 version 0.1.0
|
82
|
+
* release!
|
83
|
+
|
data/README.markdown
CHANGED
@@ -1,309 +1,312 @@
|
|
1
|
-
Pry
|
2
|
-
=============
|
3
|
-
|
4
|
-
(C) John Mair (banisterfiend) 2011
|
5
|
-
|
6
|
-
_attach an irb-like session to any object at runtime_
|
7
|
-
|
8
|
-
Pry is a simple Ruby REPL (Read-Eval-Print-Loop) that specializes in the interactive
|
9
|
-
manipulation of objects during the running of a program.
|
10
|
-
|
11
|
-
In some sense it is the opposite of IRB in that you bring a REPL
|
12
|
-
session to your code (with Pry) instead of bringing your code to a
|
13
|
-
REPL session (as with IRB).
|
14
|
-
|
15
|
-
It is not based on the IRB codebase, and implements some unique REPL
|
16
|
-
commands such as `show-method`, `show-doc`, `ls` and `cd` (type `help`
|
17
|
-
to get a full list).
|
18
|
-
|
19
|
-
Pry is also fairly flexible and allows significant user
|
20
|
-
[customization](http://rdoc.info/github/banister/pry/master/file/wiki/Customizing-pry.md). It
|
21
|
-
is trivial to set it to read from any object that has a `readline` method and write to any object that has a
|
22
|
-
`puts` method - many other aspects of Pry are also configurable making
|
23
|
-
it a good choice for implementing custom shells.
|
24
|
-
|
25
|
-
Pry now comes with an executable so it can be invoked at the command line.
|
26
|
-
Just enter `pry` to start. A `.pryrc` file in the user's home directory will
|
27
|
-
be loaded if it exists. Type `pry --help` at the command line for more information.
|
28
|
-
|
29
|
-
* Install the [gem](https://rubygems.org/gems/pry): `gem install pry`
|
30
|
-
* Read the [documentation](http://rdoc.info/github/banister/pry/master/file/README.markdown)
|
31
|
-
* See the [source code](http://github.com/banister/pry)
|
32
|
-
|
33
|
-
Pry also has `rubygems-test` support; to participate, first install
|
34
|
-
Pry, then:
|
35
|
-
|
36
|
-
1. Install rubygems-test: `gem install rubygems-test`
|
37
|
-
2. Run the test: `gem test pry`
|
38
|
-
3. Finally choose 'Yes' to upload the results.
|
39
|
-
|
40
|
-
Example: Interacting with an object at runtime
|
41
|
-
---------------------------------------
|
42
|
-
|
43
|
-
With the `Object#pry` method we can pry (open an irb-like session) on
|
44
|
-
an object. In the example below we open a Pry session for the `Test` class and execute a method and add
|
45
|
-
an instance variable. The current thread is halted for the duration of the session.
|
46
|
-
|
47
|
-
require 'pry'
|
48
|
-
|
49
|
-
class Test
|
50
|
-
def self.hello() "hello world" end
|
51
|
-
end
|
52
|
-
|
53
|
-
Test.pry
|
54
|
-
|
55
|
-
# Pry session begins on stdin
|
56
|
-
Beginning Pry session for Test
|
57
|
-
pry(Test)> self
|
58
|
-
=> Test
|
59
|
-
pry(Test)> hello
|
60
|
-
=> "hello world"
|
61
|
-
pry(Test)> @y = 20
|
62
|
-
=> 20
|
63
|
-
pry(Test)> exit
|
64
|
-
Ending Pry session for Test
|
65
|
-
|
66
|
-
# program resumes here
|
67
|
-
|
68
|
-
If we now inspect the `Test` object we can see our changes have had
|
69
|
-
effect:
|
70
|
-
|
71
|
-
Test.instance_variable_get(:@y) #=> 20
|
72
|
-
|
73
|
-
### Alternative Syntax
|
74
|
-
|
75
|
-
You can also use the `Pry.start(obj)` or `pry(obj)` syntax to start a pry session on
|
76
|
-
`obj`. e.g
|
77
|
-
|
78
|
-
Pry.start(5)
|
79
|
-
Beginning Pry session for 5
|
80
|
-
pry(5)>
|
81
|
-
|
82
|
-
OR
|
83
|
-
|
84
|
-
pry(6)
|
85
|
-
beginning Pry session for 6
|
86
|
-
pry(6)>
|
87
|
-
|
88
|
-
Example: Pry sessions can nest
|
89
|
-
-----------------------------------------------
|
90
|
-
|
91
|
-
Here we will begin Pry at top-level, then pry on a class and then on
|
92
|
-
an instance variable inside that class:
|
93
|
-
|
94
|
-
# Pry.start() without parameters begins a Pry session on top-level (main)
|
95
|
-
Pry.start
|
96
|
-
Beginning Pry session for main
|
97
|
-
pry(main)> class Hello
|
98
|
-
pry(main)* @x = 20
|
99
|
-
pry(main)* end
|
100
|
-
=> 20
|
101
|
-
pry(main)> cd Hello
|
102
|
-
Beginning Pry session for Hello
|
103
|
-
pry(Hello):1> instance_variables
|
104
|
-
=> [:@x]
|
105
|
-
pry(Hello):1> cd @x
|
106
|
-
Beginning Pry session for 20
|
107
|
-
pry(20:2)> self + 10
|
108
|
-
=> 30
|
109
|
-
pry(20:2)> cd ..
|
110
|
-
Ending Pry session for 20
|
111
|
-
pry(Hello):1> cd ..
|
112
|
-
Ending Pry session for Hello
|
113
|
-
pry(main)> cd ..
|
114
|
-
Ending Pry session for main
|
115
|
-
|
116
|
-
The number after the `:` in the pry prompt indicates the nesting
|
117
|
-
level. To display more information about nesting, use the `nesting`
|
118
|
-
command. E.g
|
119
|
-
|
120
|
-
pry("friend":3)> nesting
|
121
|
-
Nesting status:
|
122
|
-
0. main (Pry top level)
|
123
|
-
1. Hello
|
124
|
-
2. 100
|
125
|
-
3. "friend"
|
126
|
-
=> nil
|
127
|
-
|
128
|
-
We can then jump back to any of the previous nesting levels by using
|
129
|
-
the `jump-to` command:
|
130
|
-
|
131
|
-
pry("friend":3)> jump-to 1
|
132
|
-
Ending Pry session for "friend"
|
133
|
-
Ending Pry session for 100
|
134
|
-
=> 100
|
135
|
-
pry(Hello):1>
|
136
|
-
|
137
|
-
If we just want to go back one level of nesting we can of course
|
138
|
-
use the `quit` or `exit` or `back` commands.
|
139
|
-
|
140
|
-
To break out of all levels of Pry nesting and return immediately to the
|
141
|
-
calling process use `exit-all`:
|
142
|
-
|
143
|
-
pry("friend":3)> exit-all
|
144
|
-
Ending Pry session for "friend"
|
145
|
-
Ending Pry session for 100
|
146
|
-
Ending Pry session for Hello
|
147
|
-
Ending Pry session for main
|
148
|
-
=> main
|
149
|
-
|
150
|
-
# program resumes here
|
151
|
-
|
152
|
-
Features and limitations
|
153
|
-
------------------------
|
154
|
-
|
155
|
-
Pry is an irb-like clone with an emphasis on interactively examining
|
156
|
-
and manipulating objects during the running of a program.
|
157
|
-
|
158
|
-
Its primary utility is probably in debugging, though it may have other
|
159
|
-
uses (such as implementing a quake-like console for games, for example). Here is a
|
160
|
-
list of Pry's features along with some of its limitations given at the
|
161
|
-
end.
|
162
|
-
|
163
|
-
###Features:
|
164
|
-
|
165
|
-
* Pry can be invoked at any time and on any object in the running program.
|
166
|
-
* Pry sessions can nest arbitrarily deeply -- to go back one level of nesting type 'exit' or 'quit' or 'back'
|
167
|
-
*
|
168
|
-
* Use `
|
169
|
-
* Pry
|
170
|
-
* Pry
|
171
|
-
*
|
172
|
-
*
|
173
|
-
|
174
|
-
|
175
|
-
* Pry
|
176
|
-
* Pry
|
177
|
-
* Pry
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
for
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
* `
|
190
|
-
*
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
`
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
* `
|
243
|
-
* `
|
244
|
-
* `
|
245
|
-
|
246
|
-
|
247
|
-
* `
|
248
|
-
|
249
|
-
|
250
|
-
* `
|
251
|
-
|
252
|
-
* `
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
* `
|
260
|
-
|
261
|
-
*
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
* `
|
292
|
-
* `
|
293
|
-
* `
|
294
|
-
* `
|
295
|
-
* `
|
296
|
-
* `
|
297
|
-
* `
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
Pry
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
1
|
+
Pry
|
2
|
+
=============
|
3
|
+
|
4
|
+
(C) John Mair (banisterfiend) 2011
|
5
|
+
|
6
|
+
_attach an irb-like session to any object at runtime_
|
7
|
+
|
8
|
+
Pry is a simple Ruby REPL (Read-Eval-Print-Loop) that specializes in the interactive
|
9
|
+
manipulation of objects during the running of a program.
|
10
|
+
|
11
|
+
In some sense it is the opposite of IRB in that you bring a REPL
|
12
|
+
session to your code (with Pry) instead of bringing your code to a
|
13
|
+
REPL session (as with IRB).
|
14
|
+
|
15
|
+
It is not based on the IRB codebase, and implements some unique REPL
|
16
|
+
commands such as `show-method`, `show-doc`, `ls` and `cd` (type `help`
|
17
|
+
to get a full list).
|
18
|
+
|
19
|
+
Pry is also fairly flexible and allows significant user
|
20
|
+
[customization](http://rdoc.info/github/banister/pry/master/file/wiki/Customizing-pry.md). It
|
21
|
+
is trivial to set it to read from any object that has a `readline` method and write to any object that has a
|
22
|
+
`puts` method - many other aspects of Pry are also configurable making
|
23
|
+
it a good choice for implementing custom shells.
|
24
|
+
|
25
|
+
Pry now comes with an executable so it can be invoked at the command line.
|
26
|
+
Just enter `pry` to start. A `.pryrc` file in the user's home directory will
|
27
|
+
be loaded if it exists. Type `pry --help` at the command line for more information.
|
28
|
+
|
29
|
+
* Install the [gem](https://rubygems.org/gems/pry): `gem install pry`
|
30
|
+
* Read the [documentation](http://rdoc.info/github/banister/pry/master/file/README.markdown)
|
31
|
+
* See the [source code](http://github.com/banister/pry)
|
32
|
+
|
33
|
+
Pry also has `rubygems-test` support; to participate, first install
|
34
|
+
Pry, then:
|
35
|
+
|
36
|
+
1. Install rubygems-test: `gem install rubygems-test`
|
37
|
+
2. Run the test: `gem test pry`
|
38
|
+
3. Finally choose 'Yes' to upload the results.
|
39
|
+
|
40
|
+
Example: Interacting with an object at runtime
|
41
|
+
---------------------------------------
|
42
|
+
|
43
|
+
With the `Object#pry` method we can pry (open an irb-like session) on
|
44
|
+
an object. In the example below we open a Pry session for the `Test` class and execute a method and add
|
45
|
+
an instance variable. The current thread is halted for the duration of the session.
|
46
|
+
|
47
|
+
require 'pry'
|
48
|
+
|
49
|
+
class Test
|
50
|
+
def self.hello() "hello world" end
|
51
|
+
end
|
52
|
+
|
53
|
+
Test.pry
|
54
|
+
|
55
|
+
# Pry session begins on stdin
|
56
|
+
Beginning Pry session for Test
|
57
|
+
pry(Test)> self
|
58
|
+
=> Test
|
59
|
+
pry(Test)> hello
|
60
|
+
=> "hello world"
|
61
|
+
pry(Test)> @y = 20
|
62
|
+
=> 20
|
63
|
+
pry(Test)> exit
|
64
|
+
Ending Pry session for Test
|
65
|
+
|
66
|
+
# program resumes here
|
67
|
+
|
68
|
+
If we now inspect the `Test` object we can see our changes have had
|
69
|
+
effect:
|
70
|
+
|
71
|
+
Test.instance_variable_get(:@y) #=> 20
|
72
|
+
|
73
|
+
### Alternative Syntax
|
74
|
+
|
75
|
+
You can also use the `Pry.start(obj)` or `pry(obj)` syntax to start a pry session on
|
76
|
+
`obj`. e.g
|
77
|
+
|
78
|
+
Pry.start(5)
|
79
|
+
Beginning Pry session for 5
|
80
|
+
pry(5)>
|
81
|
+
|
82
|
+
OR
|
83
|
+
|
84
|
+
pry(6)
|
85
|
+
beginning Pry session for 6
|
86
|
+
pry(6)>
|
87
|
+
|
88
|
+
Example: Pry sessions can nest
|
89
|
+
-----------------------------------------------
|
90
|
+
|
91
|
+
Here we will begin Pry at top-level, then pry on a class and then on
|
92
|
+
an instance variable inside that class:
|
93
|
+
|
94
|
+
# Pry.start() without parameters begins a Pry session on top-level (main)
|
95
|
+
Pry.start
|
96
|
+
Beginning Pry session for main
|
97
|
+
pry(main)> class Hello
|
98
|
+
pry(main)* @x = 20
|
99
|
+
pry(main)* end
|
100
|
+
=> 20
|
101
|
+
pry(main)> cd Hello
|
102
|
+
Beginning Pry session for Hello
|
103
|
+
pry(Hello):1> instance_variables
|
104
|
+
=> [:@x]
|
105
|
+
pry(Hello):1> cd @x
|
106
|
+
Beginning Pry session for 20
|
107
|
+
pry(20:2)> self + 10
|
108
|
+
=> 30
|
109
|
+
pry(20:2)> cd ..
|
110
|
+
Ending Pry session for 20
|
111
|
+
pry(Hello):1> cd ..
|
112
|
+
Ending Pry session for Hello
|
113
|
+
pry(main)> cd ..
|
114
|
+
Ending Pry session for main
|
115
|
+
|
116
|
+
The number after the `:` in the pry prompt indicates the nesting
|
117
|
+
level. To display more information about nesting, use the `nesting`
|
118
|
+
command. E.g
|
119
|
+
|
120
|
+
pry("friend":3)> nesting
|
121
|
+
Nesting status:
|
122
|
+
0. main (Pry top level)
|
123
|
+
1. Hello
|
124
|
+
2. 100
|
125
|
+
3. "friend"
|
126
|
+
=> nil
|
127
|
+
|
128
|
+
We can then jump back to any of the previous nesting levels by using
|
129
|
+
the `jump-to` command:
|
130
|
+
|
131
|
+
pry("friend":3)> jump-to 1
|
132
|
+
Ending Pry session for "friend"
|
133
|
+
Ending Pry session for 100
|
134
|
+
=> 100
|
135
|
+
pry(Hello):1>
|
136
|
+
|
137
|
+
If we just want to go back one level of nesting we can of course
|
138
|
+
use the `quit` or `exit` or `back` commands.
|
139
|
+
|
140
|
+
To break out of all levels of Pry nesting and return immediately to the
|
141
|
+
calling process use `exit-all`:
|
142
|
+
|
143
|
+
pry("friend":3)> exit-all
|
144
|
+
Ending Pry session for "friend"
|
145
|
+
Ending Pry session for 100
|
146
|
+
Ending Pry session for Hello
|
147
|
+
Ending Pry session for main
|
148
|
+
=> main
|
149
|
+
|
150
|
+
# program resumes here
|
151
|
+
|
152
|
+
Features and limitations
|
153
|
+
------------------------
|
154
|
+
|
155
|
+
Pry is an irb-like clone with an emphasis on interactively examining
|
156
|
+
and manipulating objects during the running of a program.
|
157
|
+
|
158
|
+
Its primary utility is probably in debugging, though it may have other
|
159
|
+
uses (such as implementing a quake-like console for games, for example). Here is a
|
160
|
+
list of Pry's features along with some of its limitations given at the
|
161
|
+
end.
|
162
|
+
|
163
|
+
###Features:
|
164
|
+
|
165
|
+
* Pry can be invoked at any time and on any object in the running program.
|
166
|
+
* Pry sessions can nest arbitrarily deeply -- to go back one level of nesting type 'exit' or 'quit' or 'back'
|
167
|
+
* Pry comes with syntax highlighting just use the `toggle-color` command to use it.
|
168
|
+
* Use `_` to recover last result.
|
169
|
+
* Use `_pry_` to reference the Pry instance managing the current session.
|
170
|
+
* Pry supports tab completion.
|
171
|
+
* Pry has multi-line support built in.
|
172
|
+
* Use `^d` (control-d) to quickly break out of a session.
|
173
|
+
* Pry has special commands not found in many other Ruby REPLs: `show-method`, `show-doc`
|
174
|
+
`jump-to`, `ls`, `cd`, `cat`
|
175
|
+
* Pry gives good control over nested sessions (important when exploring complicated runtime state)
|
176
|
+
* Pry is not based on the IRB codebase.
|
177
|
+
* Pry allows significant customizability.
|
178
|
+
* Pry uses the [method_source](https://github.com/banister/method_source) gem; so
|
179
|
+
this functionality is available to a Pry session.
|
180
|
+
* Pry uses [RubyParser](https://github.com/seattlerb/ruby_parser) to
|
181
|
+
validate expressions in 1.8, and [Ripper](http://rdoc.info/docs/ruby-core/1.9.2/Ripper) for 1.9.
|
182
|
+
* Pry implements all the methods in the REPL chain separately: `Pry#r`
|
183
|
+
for reading; `Pry#re` for eval; `Pry#rep` for printing; and `Pry#repl`
|
184
|
+
for the loop (`Pry.start` simply wraps `Pry.new.repl`). You can
|
185
|
+
invoke any of these methods directly depending on exactly what aspect of the functionality you need.
|
186
|
+
|
187
|
+
###Limitations:
|
188
|
+
|
189
|
+
* Some Pry commands (e.g `show-command`) do not work in Ruby 1.8.
|
190
|
+
* `method_source` functionality does not work in JRuby.
|
191
|
+
* 1.9 support requires `Ripper` - some implementations may not support this.
|
192
|
+
|
193
|
+
Commands
|
194
|
+
-----------
|
195
|
+
|
196
|
+
### The Pry API:
|
197
|
+
|
198
|
+
* `Pry.start()` Starts a Read-Eval-Print-Loop on the object it
|
199
|
+
receives as a parameter. In the case of no parameter it operates on
|
200
|
+
top-level (main). It can receive any object or a `Binding`
|
201
|
+
object as parameter. `Pry.start()` is implemented as `Pry.new.repl()`
|
202
|
+
* `obj.pry` and `pry(obj)` may also be used as alternative syntax to
|
203
|
+
`Pry.start(obj)`.
|
204
|
+
|
205
|
+
However there are some differences. `obj.pry` opens
|
206
|
+
a Pry session on the receiver whereas `Pry.start` (with no parameter)
|
207
|
+
will start a Pry session on top-level. The other form of the `pry`
|
208
|
+
method: `pry(obj)` will also start a Pry session on its parameter.
|
209
|
+
|
210
|
+
The `pry` method invoked by itself, with no explict receiver and no
|
211
|
+
parameter will start a Pry session on the implied receiver. It is
|
212
|
+
perhaps more useful to invoke it in this form `pry(binding)` or
|
213
|
+
`binding.pry` so as to get access to locals in the current context.
|
214
|
+
|
215
|
+
Another difference is that `Pry.start()` accepts a second parameter
|
216
|
+
that is a hash of configuration options (discussed further, below).
|
217
|
+
|
218
|
+
* If, for some reason you do not want to 'loop' then use `Pry.new.rep()`; it
|
219
|
+
only performs the Read-Eval-Print section of the REPL - it ends the
|
220
|
+
session after just one line of input. It takes the same parameters as
|
221
|
+
`Pry#repl()`
|
222
|
+
* Likewise `Pry#re()` only performs the Read-Eval section of the REPL,
|
223
|
+
it returns the result of the evaluation or an Exception object in
|
224
|
+
case of error. It also takes the same parameters as `Pry#repl()`
|
225
|
+
* Similarly `Pry#r()` only performs the Read section of the REPL, only
|
226
|
+
returning the Ruby expression (as a string). It takes the same parameters as all the others.
|
227
|
+
* `Pry.run_command COMMAND` enables you to invoke Pry commands outside
|
228
|
+
of a session, e.g `Pry.run_command "ls -m", :context => MyObject`. See
|
229
|
+
docs for more info.
|
230
|
+
|
231
|
+
### Session commands
|
232
|
+
|
233
|
+
Pry supports a few commands inside the session itself. These commands are
|
234
|
+
not methods and must start at the beginning of a line, with no
|
235
|
+
whitespace in between.
|
236
|
+
|
237
|
+
If you want to access a method of the same name, prefix the invocation by whitespace.
|
238
|
+
|
239
|
+
* Typing `!` on a line by itself will clear the input buffer - useful for
|
240
|
+
getting you out of a situation where the parsing process
|
241
|
+
goes wrong and you get stuck in an endless read loop.
|
242
|
+
* `status` shows status information about the current session.
|
243
|
+
* `version` Show Pry version information
|
244
|
+
* `help` shows the list of session commands with brief explanations.
|
245
|
+
* `toggle-color` turns on and off syntax highlighting.
|
246
|
+
* `simple-prompt` toggles the simple prompt mode.
|
247
|
+
* `exit` or `quit` or `back` or `^d` (control-d) will end the current Pry session and go
|
248
|
+
back to the calling process or back one level of nesting (if there
|
249
|
+
are nested sessions).
|
250
|
+
* `ls [OPTIONS] [VAR]` returns a list of local variables, instance variables, and
|
251
|
+
methods, etc. Highly flexible. See `ls --help` for more info.
|
252
|
+
* `cat VAR` Calls `inspect` on `VAR`
|
253
|
+
* `cd VAR` Starts a `Pry` session on the variable VAR. E.g `cd @x`
|
254
|
+
(use `cd ..` to go back).
|
255
|
+
* `show-method [OPTIONS] METH` Displays the sourcecode for the method
|
256
|
+
`METH`. e.g `show-method hello`. See `show-method --help` for more info.
|
257
|
+
* `show-doc [OPTIONS] METH` Displays comments for `METH`. See `show-doc
|
258
|
+
--help` for more info.
|
259
|
+
* `show-command COMMAND` Displays the sourcecode for the given Pry
|
260
|
+
command. e.g: `show-command cd`
|
261
|
+
* `jump-to NEST_LEVEL` Unwinds the Pry stack (nesting level) until the appropriate nesting level is reached.
|
262
|
+
* `exit-all` breaks out of all Pry nesting levels and returns to the
|
263
|
+
calling process.
|
264
|
+
* You can type `Pry.start(obj)` or `obj.pry` to nest another Pry session within the
|
265
|
+
current one with `obj` as the receiver of the new session. Very useful
|
266
|
+
when exploring large or complicated runtime state.
|
267
|
+
|
268
|
+
Bindings and objects
|
269
|
+
--------------------
|
270
|
+
|
271
|
+
Pry ultimately operates on `Binding` objects. If you invoke Pry with a
|
272
|
+
Binding object it uses that Binding. If you invoke Pry with anything
|
273
|
+
other than a `Binding`, Pry will generate a Binding for that
|
274
|
+
object and use that.
|
275
|
+
|
276
|
+
If you want to open a Pry session on the current context and capture
|
277
|
+
the locals you should use: `binding.pry`. If you do not care about
|
278
|
+
capturing the locals you can simply use `pry` (which will generate a
|
279
|
+
fresh `Binding` for the receiver).
|
280
|
+
|
281
|
+
Top-level is a special case; you can start a Pry session on top-level
|
282
|
+
*and* capture locals by simply using: `pry`. This is because Pry
|
283
|
+
automatically uses `TOPLEVEL_BINDING` for the top-level object (main).
|
284
|
+
|
285
|
+
Example Programs
|
286
|
+
----------------
|
287
|
+
|
288
|
+
Pry comes bundled with a few example programs to illustrate some
|
289
|
+
features, see the `examples/` directory.
|
290
|
+
|
291
|
+
* `example_basic.rb` - Demonstrate basic Pry functionality
|
292
|
+
* `example_input.rb` - Demonstrates how to set the `input` object.
|
293
|
+
* `example_output.rb` - Demonstrates how to set the `output` object.
|
294
|
+
* `example_hooks.rb` - Demonstrates how to set the `hooks` hash.
|
295
|
+
* `example_print.rb` - Demonstrates how to set the `print` object.
|
296
|
+
* `example_prompt.rb` - Demonstrates how to set the `prompt`.
|
297
|
+
* `example_input2.rb` - An advanced `input` example.
|
298
|
+
* `example_commands.rb` - Implementing a mathematical command set.
|
299
|
+
* `example_commands_override.rb` - An advanced `commands` example.
|
300
|
+
* `example_image_edit.rb` - A simple image editor using a Pry REPL (requires `Gosu` and `TexPlay` gems).
|
301
|
+
|
302
|
+
Customizing Pry
|
303
|
+
---------------
|
304
|
+
|
305
|
+
Pry allows a large degree of customization.
|
306
|
+
|
307
|
+
[Read how to customize Pry here.](http://rdoc.info/github/banister/pry/master/file/wiki/Customizing-pry.md)
|
308
|
+
|
309
|
+
Contact
|
310
|
+
-------
|
311
|
+
|
312
|
+
Problems or questions contact me at [github](http://github.com/banister)
|