pry 0.8.2-i386-mswin32 → 0.8.3-i386-mswin32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.markdown +62 -39
- data/Rakefile +7 -6
- data/bin/pry +1 -6
- data/lib/pry.rb +11 -15
- data/lib/pry/command_base.rb +1 -2
- data/lib/pry/command_helpers.rb +21 -2
- data/lib/pry/commands.rb +59 -10
- data/lib/pry/pry_class.rb +14 -0
- data/lib/pry/pry_instance.rb +4 -17
- data/lib/pry/version.rb +1 -1
- data/test/test.rb +4 -2
- metadata +3 -3
data/README.markdown
CHANGED
@@ -11,6 +11,7 @@ these include:
|
|
11
11
|
* Source code browsing (including core C source with the pry-doc gem)
|
12
12
|
* Documentation browsing
|
13
13
|
* Live help system
|
14
|
+
* Open methods in editors (`edit-method Class#method`)
|
14
15
|
* Syntax highlighting
|
15
16
|
* Command shell integration (start editors, run git, and rake from within Pry)
|
16
17
|
* Gist integration
|
@@ -113,7 +114,10 @@ the `jump-to` command:
|
|
113
114
|
|
114
115
|
Pry can be invoked in the middle of a running program. It opens a Pry
|
115
116
|
session at the point it's called and makes all program state at that
|
116
|
-
point available.
|
117
|
+
point available. It can be invoked on any object using the
|
118
|
+
`my_object.pry` syntax or on the current binding (or any binding)
|
119
|
+
using `binding.pry`. The Pry session will then begin within the scope
|
120
|
+
of the object (or binding). When the session ends the program continues with any
|
117
121
|
modifications you made to it.
|
118
122
|
|
119
123
|
This functionality can be used for such things as: debugging,
|
@@ -123,16 +127,16 @@ code:
|
|
123
127
|
|
124
128
|
# test.rb
|
125
129
|
require 'pry'
|
126
|
-
|
130
|
+
|
127
131
|
class A
|
128
132
|
def hello() puts "hello world!" end
|
129
133
|
end
|
130
|
-
|
134
|
+
|
131
135
|
a = A.new
|
132
|
-
|
136
|
+
|
133
137
|
# start a REPL session
|
134
138
|
binding.pry
|
135
|
-
|
139
|
+
|
136
140
|
# program resumes here (after pry session)
|
137
141
|
puts "program resumes here."
|
138
142
|
|
@@ -166,8 +170,8 @@ using the normal `#{}` string interpolation syntax.
|
|
166
170
|
In the code below we're going to switch to `shell-mode` and edit the
|
167
171
|
`.pryrc` file in the home directory. We'll then cat its contents and
|
168
172
|
reload the file.
|
169
|
-
|
170
|
-
pry(main)> shell-mode
|
173
|
+
|
174
|
+
pry(main)> shell-mode
|
171
175
|
pry main:/home/john/ruby/projects/pry $ .cd ~
|
172
176
|
pry main:/home/john $ .emacsclient .pryrc
|
173
177
|
pry main:/home/john $ .cat .pryrc
|
@@ -176,7 +180,7 @@ reload the file.
|
|
176
180
|
end
|
177
181
|
pry main:/home/john $ load ".pryrc"
|
178
182
|
=> true
|
179
|
-
pry main:/home/john $ hello_world
|
183
|
+
pry main:/home/john $ hello_world
|
180
184
|
hello world!
|
181
185
|
|
182
186
|
We can also interpolate Ruby code into the shell. In the
|
@@ -186,7 +190,7 @@ current directory and count the number of lines in that file with
|
|
186
190
|
|
187
191
|
pry main:/home/john $ .cat #{Dir['*.*'].sample} | wc -l
|
188
192
|
44
|
189
|
-
|
193
|
+
|
190
194
|
### Code Browsing
|
191
195
|
|
192
196
|
#### show-method
|
@@ -203,37 +207,37 @@ include line numbers in the output.
|
|
203
207
|
|
204
208
|
In the following example we will enter the `Pry` class, list the
|
205
209
|
instance methods beginning with 're' and display the source code for the `rep` method:
|
206
|
-
|
210
|
+
|
207
211
|
pry(main)> cd Pry
|
208
212
|
pry(Pry):1> ls -M --grep ^re
|
209
213
|
[:re, :readline, :rep, :repl, :repl_epilogue, :repl_prologue, :retrieve_line]
|
210
214
|
pry(Pry):1> show-method rep -l
|
211
|
-
|
215
|
+
|
212
216
|
From: /home/john/ruby/projects/pry/lib/pry/pry_instance.rb @ line 143:
|
213
217
|
Number of lines: 6
|
214
|
-
|
218
|
+
|
215
219
|
143: def rep(target=TOPLEVEL_BINDING)
|
216
220
|
144: target = Pry.binding_for(target)
|
217
221
|
145: result = re(target)
|
218
|
-
146:
|
222
|
+
146:
|
219
223
|
147: show_result(result) if should_print?
|
220
224
|
148: end
|
221
225
|
|
222
226
|
Note that we can also view C methods (from Ruby Core) using the
|
223
227
|
`pry-doc` gem; we also show off the alternate syntax for
|
224
228
|
`show-method`:
|
225
|
-
|
229
|
+
|
226
230
|
pry(main)> show-method Array#select
|
227
|
-
|
231
|
+
|
228
232
|
From: array.c in Ruby Core (C Method):
|
229
233
|
Number of lines: 15
|
230
|
-
|
234
|
+
|
231
235
|
static VALUE
|
232
236
|
rb_ary_select(VALUE ary)
|
233
237
|
{
|
234
238
|
VALUE result;
|
235
239
|
long i;
|
236
|
-
|
240
|
+
|
237
241
|
RETURN_ENUMERATOR(ary, 0, 0);
|
238
242
|
result = rb_ary_new2(RARRAY_LEN(ary));
|
239
243
|
for (i = 0; i < RARRAY_LEN(ary); i++) {
|
@@ -256,14 +260,14 @@ commands to do such things as change directory into the directory
|
|
256
260
|
containing the file, open the file in an editor, display the file using `cat`, and so on.
|
257
261
|
|
258
262
|
In the following example we wil use Pry to fix a bug in a method:
|
259
|
-
|
263
|
+
|
260
264
|
pry(main)> greet "john"
|
261
265
|
hello johnhow are you?=> nil
|
262
266
|
pry(main)> show-method greet
|
263
|
-
|
267
|
+
|
264
268
|
From: /Users/john/ruby/play/bug.rb @ line 2:
|
265
269
|
Number of lines: 4
|
266
|
-
|
270
|
+
|
267
271
|
def greet(name)
|
268
272
|
print "hello #{name}"
|
269
273
|
print "how are you?"
|
@@ -275,10 +279,10 @@ In the following example we wil use Pry to fix a bug in a method:
|
|
275
279
|
how are you?
|
276
280
|
=> nil
|
277
281
|
pry(main)> show-method greet
|
278
|
-
|
282
|
+
|
279
283
|
From: /Users/john/ruby/play/bug.rb @ line 2:
|
280
284
|
Number of lines: 4
|
281
|
-
|
285
|
+
|
282
286
|
def greet(name)
|
283
287
|
puts "hello #{name}"
|
284
288
|
puts "how are you?"
|
@@ -314,10 +318,10 @@ documentation for the `try_activate` method:
|
|
314
318
|
|
315
319
|
pry(main)> cd Gem
|
316
320
|
pry(Gem):1> show-doc try_activate
|
317
|
-
|
321
|
+
|
318
322
|
From: /Users/john/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems.rb @ line 201:
|
319
323
|
Number of lines: 3
|
320
|
-
|
324
|
+
|
321
325
|
Try to activate a gem containing path. Returns true if
|
322
326
|
activation succeeded or wasn't needed because it was already
|
323
327
|
activated. Returns false if it can't find the path in a gem.
|
@@ -331,14 +335,14 @@ We can also use `ri` in the normal way:
|
|
331
335
|
------------------------------------------------------------------------
|
332
336
|
Calls _block_ once for each element in _self_, passing that element
|
333
337
|
as a parameter.
|
334
|
-
|
338
|
+
|
335
339
|
a = [ "a", "b", "c" ]
|
336
340
|
a.each {|x| print x, " -- " }
|
337
|
-
|
341
|
+
|
338
342
|
produces:
|
339
|
-
|
343
|
+
|
340
344
|
a -- b -- c --
|
341
|
-
|
345
|
+
|
342
346
|
|
343
347
|
### History
|
344
348
|
|
@@ -350,7 +354,7 @@ history can be replayed.
|
|
350
354
|
|
351
355
|
In the example below we will enter a few lines in a Pry session and
|
352
356
|
then view history; we will then replay one of those lines:
|
353
|
-
|
357
|
+
|
354
358
|
pry(main)> hist
|
355
359
|
0: hist -h
|
356
360
|
1: ls
|
@@ -359,10 +363,10 @@ then view history; we will then replay one of those lines:
|
|
359
363
|
4: x = rand
|
360
364
|
5: hist
|
361
365
|
pry(main)> hist --replay 3
|
362
|
-
|
366
|
+
|
363
367
|
From: io.c in Ruby Core (C Method):
|
364
368
|
Number of lines: 8
|
365
|
-
|
369
|
+
|
366
370
|
static VALUE
|
367
371
|
rb_f_puts(int argc, VALUE *argv, VALUE recv)
|
368
372
|
{
|
@@ -371,7 +375,7 @@ then view history; we will then replay one of those lines:
|
|
371
375
|
}
|
372
376
|
return rb_funcall2(rb_stdout, rb_intern("puts"), argc, argv);
|
373
377
|
}
|
374
|
-
|
378
|
+
|
375
379
|
In the next example we will replay a range of lines in history. Note
|
376
380
|
that we replay to a point where a class definition is still open and so
|
377
381
|
we can continue to add instance methods to the class:
|
@@ -394,7 +398,7 @@ we can continue to add instance methods to the class:
|
|
394
398
|
pry(main)>
|
395
399
|
|
396
400
|
Also note that in the above the line `Hello.new.goodbye_world;` ends
|
397
|
-
with a semi-colon which causes expression evaluation output to be suppressed.
|
401
|
+
with a semi-colon which causes expression evaluation output to be suppressed.
|
398
402
|
|
399
403
|
### Gist integration
|
400
404
|
|
@@ -402,12 +406,31 @@ If the `gist` gem is installed then method source or documentation can be gisted
|
|
402
406
|
`gist-method` command. The `gist-method` command accepts the same two
|
403
407
|
syntaxes as `show-method`. In the example below we will gist the C source
|
404
408
|
code for the `Symbol#to_proc` method to github:
|
405
|
-
|
409
|
+
|
406
410
|
pry(main)> gist-method Symbol#to_proc
|
407
411
|
https://gist.github.com/5332c38afc46d902ce46
|
408
|
-
pry(main)>
|
409
|
-
|
410
|
-
You can see the actual gist generated here: https://gist.github.com/5332c38afc46d902ce46
|
412
|
+
pry(main)>
|
413
|
+
|
414
|
+
You can see the actual gist generated here: [https://gist.github.com/5332c38afc46d902ce46](https://gist.github.com/5332c38afc46d902ce46)
|
415
|
+
|
416
|
+
### Edit methods
|
417
|
+
|
418
|
+
You can use `edit-method Class#method` or `edit-method my_method`
|
419
|
+
(if the method is in scope) to open a method for editing directly in
|
420
|
+
your favorite editor. Pry has knowledge of a few different editors and
|
421
|
+
will attempt to open the file at the line the method is defined.
|
422
|
+
|
423
|
+
You can set the editor to use by assigning to the `Pry.editor=`
|
424
|
+
accessor. `Pry.editor` will default to `$EDITOR` or failing that will
|
425
|
+
use `nano` as the backup default. The file that is edited will be
|
426
|
+
automatically reloaded after exiting the editor - reloading can be
|
427
|
+
suppressed by passing the --no-reload option to `edit-method`
|
428
|
+
|
429
|
+
In the example below we will set our default editor to "emacsclient"
|
430
|
+
and open the `Pry#repl` method for editing:
|
431
|
+
|
432
|
+
pry(main)> Pry.editor = "emacsclient"
|
433
|
+
pry(main)> edit-method Pry#repl
|
411
434
|
|
412
435
|
|
413
436
|
### Live Help System
|
@@ -468,7 +491,7 @@ invoke any of these methods directly depending on exactly what aspect of the fun
|
|
468
491
|
limitation in JRuby's regex).
|
469
492
|
* Tab completion is currently a bit broken/limited this will have a
|
470
493
|
major overhaul in a future version.
|
471
|
-
|
494
|
+
|
472
495
|
### Syntax Highlighting
|
473
496
|
|
474
497
|
Syntax highlighting is on by default in Pry. You can toggle it on and
|
@@ -494,7 +517,7 @@ features, see the `examples/` directory.
|
|
494
517
|
|
495
518
|
### Customizing Pry
|
496
519
|
|
497
|
-
Pry allows a large degree of customization.
|
520
|
+
Pry allows a large degree of customization.
|
498
521
|
|
499
522
|
[Read how to customize Pry here.](http://rdoc.info/github/banister/pry/master/file/wiki/Customizing-pry.md)
|
500
523
|
|
data/Rakefile
CHANGED
@@ -21,7 +21,7 @@ def apply_spec_defaults(s)
|
|
21
21
|
s.require_path = 'lib'
|
22
22
|
s.add_dependency("ruby_parser",">=2.0.5")
|
23
23
|
s.add_dependency("coderay",">=0.9.7")
|
24
|
-
s.add_dependency("slop",">=1.5.
|
24
|
+
s.add_dependency("slop",">=1.5.3")
|
25
25
|
s.add_development_dependency("bacon",">=1.1.0")
|
26
26
|
s.homepage = "http://banisterfiend.wordpress.com"
|
27
27
|
s.has_rdoc = 'yard'
|
@@ -36,7 +36,8 @@ end
|
|
36
36
|
|
37
37
|
desc "run pry"
|
38
38
|
task :pry do
|
39
|
-
|
39
|
+
$LOAD_PATH.unshift "#{direc}/lib"
|
40
|
+
require 'pry'
|
40
41
|
binding.pry
|
41
42
|
end
|
42
43
|
|
@@ -51,7 +52,7 @@ namespace :ruby do
|
|
51
52
|
s.add_dependency("method_source",">=0.4.0")
|
52
53
|
s.platform = Gem::Platform::RUBY
|
53
54
|
end
|
54
|
-
|
55
|
+
|
55
56
|
Rake::GemPackageTask.new(spec) do |pkg|
|
56
57
|
pkg.need_zip = false
|
57
58
|
pkg.need_tar = false
|
@@ -61,7 +62,7 @@ end
|
|
61
62
|
[:mingw32, :mswin32].each do |v|
|
62
63
|
namespace v do
|
63
64
|
spec = Gem::Specification.new do |s|
|
64
|
-
apply_spec_defaults(s)
|
65
|
+
apply_spec_defaults(s)
|
65
66
|
s.add_dependency("method_source",">=0.4.0")
|
66
67
|
s.add_dependency("win32console", ">=1.3.0")
|
67
68
|
s.platform = "i386-#{v}"
|
@@ -80,7 +81,7 @@ namespace :jruby do
|
|
80
81
|
s.add_dependency("method_source",">=0.4.0")
|
81
82
|
s.platform = "java"
|
82
83
|
end
|
83
|
-
|
84
|
+
|
84
85
|
Rake::GemPackageTask.new(spec) do |pkg|
|
85
86
|
pkg.need_zip = false
|
86
87
|
pkg.need_tar = false
|
@@ -89,7 +90,7 @@ end
|
|
89
90
|
|
90
91
|
|
91
92
|
desc "build all platform gems at once"
|
92
|
-
task :gems => [:rmgems, "ruby:gem", "jruby:gem", "mswin32:gem", "mingw32:gem"]
|
93
|
+
task :gems => [:clean, :rmgems, "ruby:gem", "jruby:gem", "mswin32:gem", "mingw32:gem"]
|
93
94
|
|
94
95
|
desc "remove all platform gems"
|
95
96
|
task :rmgems => ["ruby:clobber_package"]
|
data/bin/pry
CHANGED
@@ -10,7 +10,7 @@ rescue LoadError
|
|
10
10
|
require 'pry'
|
11
11
|
end
|
12
12
|
|
13
|
-
opts = Slop.parse do
|
13
|
+
opts = Slop.parse(:help => true) do
|
14
14
|
banner %{Usage: pry [OPTIONS]
|
15
15
|
Start a Pry session.
|
16
16
|
See: `https://github.com/banister` for more information.
|
@@ -43,11 +43,6 @@ See: `https://github.com/banister` for more information.
|
|
43
43
|
true,
|
44
44
|
:default => "TOPLEVEL_BINDING"
|
45
45
|
)
|
46
|
-
|
47
|
-
on :h, :help, "This message" do
|
48
|
-
puts help
|
49
|
-
exit
|
50
|
-
end
|
51
46
|
end
|
52
47
|
|
53
48
|
# invoked via cli
|
data/lib/pry.rb
CHANGED
@@ -1,10 +1,6 @@
|
|
1
1
|
# (C) John Mair (banisterfiend) 2011
|
2
2
|
# MIT License
|
3
3
|
|
4
|
-
direc = File.dirname(__FILE__)
|
5
|
-
|
6
|
-
$LOAD_PATH << File.expand_path(direc)
|
7
|
-
|
8
4
|
require "method_source"
|
9
5
|
require 'shellwords'
|
10
6
|
require "readline"
|
@@ -20,17 +16,17 @@ if RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/
|
|
20
16
|
end
|
21
17
|
end
|
22
18
|
|
23
|
-
require "
|
24
|
-
require "
|
25
|
-
require "
|
26
|
-
require "
|
27
|
-
require "
|
28
|
-
require "
|
29
|
-
require "
|
30
|
-
require "
|
31
|
-
require "
|
32
|
-
require "
|
33
|
-
require "
|
19
|
+
require "pry/version"
|
20
|
+
require "pry/hooks"
|
21
|
+
require "pry/print"
|
22
|
+
require "pry/command_base"
|
23
|
+
require "pry/commands"
|
24
|
+
require "pry/prompts"
|
25
|
+
require "pry/custom_completions"
|
26
|
+
require "pry/completion"
|
27
|
+
require "pry/core_extensions"
|
28
|
+
require "pry/pry_class"
|
29
|
+
require "pry/pry_instance"
|
34
30
|
|
35
31
|
|
36
32
|
# TEMPORARY HACK FOR BUG IN JRUBY 1.9 REGEX (which kills CodeRay)
|
data/lib/pry/command_base.rb
CHANGED
data/lib/pry/command_helpers.rb
CHANGED
@@ -56,9 +56,28 @@ class Pry
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
def
|
59
|
+
def editor_with_start_line(line_number)
|
60
|
+
case Pry.editor
|
61
|
+
when /^[gm]?vi/, /^emacs/, /^nano/, /^pico/, /^gedit/, /^kate/
|
62
|
+
"#{Pry.editor} +#{line_number}"
|
63
|
+
when /^mate/
|
64
|
+
"#{Pry.editor} -l#{line_number}"
|
65
|
+
else
|
66
|
+
if RUBY_PLATFORM =~ /mswin|mingw/
|
67
|
+
Pry.editor
|
68
|
+
else
|
69
|
+
"#{Pry.editor} +#{line_number}"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def is_a_dynamically_defined_method?(meth)
|
60
75
|
file, _ = meth.source_location
|
61
|
-
|
76
|
+
!!(file =~ /(\(.*\))|<.*>/)
|
77
|
+
end
|
78
|
+
|
79
|
+
def check_for_dynamically_defined_method(meth)
|
80
|
+
if is_a_dynamically_defined_method?(meth)
|
62
81
|
raise "Cannot retrieve source for dynamically defined method."
|
63
82
|
end
|
64
83
|
end
|
data/lib/pry/commands.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
direc = File.dirname(__FILE__)
|
2
|
-
|
3
1
|
require "optparse"
|
4
2
|
require "method_source"
|
5
3
|
require 'slop'
|
6
4
|
require 'rubygems/dependency_installer'
|
7
|
-
require "
|
8
|
-
require "
|
9
|
-
require "
|
5
|
+
require "pry/command_base"
|
6
|
+
require "pry/pry_instance"
|
7
|
+
require "pry/command_helpers"
|
10
8
|
|
11
9
|
class Pry
|
12
10
|
|
@@ -52,6 +50,57 @@ class Pry
|
|
52
50
|
Pry.active_instance.input = StringIO.new(actions)
|
53
51
|
end
|
54
52
|
|
53
|
+
command "edit-method", "Edit a method. Type `edit-method --help` for more info." do |*args|
|
54
|
+
target = target()
|
55
|
+
|
56
|
+
opts = Slop.parse!(args) do |opts|
|
57
|
+
opts.banner %{Usage: edit-method [OPTIONS] [METH]
|
58
|
+
Edit the method METH in an editor.
|
59
|
+
Ensure #{bold("Pry.editor")} is set to your editor of choice.
|
60
|
+
e.g: edit-method hello_method
|
61
|
+
--
|
62
|
+
}
|
63
|
+
opts.on :M, "instance-methods", "Operate on instance methods."
|
64
|
+
opts.on :m, :methods, "Operate on methods."
|
65
|
+
opts.on "no-reload", "Do not automatically reload the method's file after editting."
|
66
|
+
opts.on :c, :context, "Select object context to run under.", true do |context|
|
67
|
+
target = Pry.binding_for(target.eval(context))
|
68
|
+
end
|
69
|
+
opts.on :h, :help, "This message." do
|
70
|
+
output.puts opts
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
next if opts.help?
|
75
|
+
|
76
|
+
meth_name = args.shift
|
77
|
+
if meth_name
|
78
|
+
if meth_name =~ /\A([^\.\#]+)[\.\#](.+)\z/ && !opts.context?
|
79
|
+
context, meth_name = $1, $2
|
80
|
+
target = Pry.binding_for(target.eval(context))
|
81
|
+
end
|
82
|
+
else
|
83
|
+
meth_name = meth_name_from_binding(target)
|
84
|
+
end
|
85
|
+
|
86
|
+
if (meth = get_method_object(meth_name, target, opts.to_hash(true))).nil?
|
87
|
+
output.puts "Invalid method name: #{meth_name}."
|
88
|
+
next
|
89
|
+
end
|
90
|
+
|
91
|
+
next output.puts "Error: No editor set!\nEnsure that #{bold("Pry.editor")} is set to your editor of choice." if !Pry.editor
|
92
|
+
|
93
|
+
if is_a_c_method?(meth)
|
94
|
+
output.puts "Error: Can't edit a C method."
|
95
|
+
elsif is_a_dynamically_defined_method?(meth)
|
96
|
+
output.puts "Error: Can't edit an eval method."
|
97
|
+
else
|
98
|
+
file, line = meth.source_location
|
99
|
+
run ".#{editor_with_start_line(line)}", file
|
100
|
+
load file if !opts["no-reload"]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
55
104
|
command "exit-program", "End the current program. Aliases: quit-program, !!!" do
|
56
105
|
exit
|
57
106
|
end
|
@@ -118,7 +167,7 @@ e.g: stat hello_method
|
|
118
167
|
else
|
119
168
|
meth_name = meth_name_from_binding(target)
|
120
169
|
end
|
121
|
-
|
170
|
+
|
122
171
|
if (meth = get_method_object(meth_name, target, opts.to_hash(true))).nil?
|
123
172
|
output.puts "Invalid method name: #{meth_name}. Type `stat --help` for help"
|
124
173
|
next
|
@@ -145,7 +194,7 @@ e.g: stat hello_method
|
|
145
194
|
|
146
195
|
command "gist-method", "Gist a method to github. Type `gist-method --help` for more info.", :requires_gem => "gist" do |*args|
|
147
196
|
target = target()
|
148
|
-
|
197
|
+
|
149
198
|
opts = Slop.parse!(args) do |opts|
|
150
199
|
opts.banner = %{Usage: gist-method [OPTIONS] [METH]
|
151
200
|
Gist the method (doc or source) to github.
|
@@ -165,17 +214,17 @@ e.g: gist -d my_method
|
|
165
214
|
next if opts.help?
|
166
215
|
|
167
216
|
# This needs to be extracted into its own method as it's shared
|
168
|
-
# by show-method and show-doc and stat commands
|
217
|
+
# by show-method and show-doc and stat commands
|
169
218
|
meth_name = args.shift
|
170
219
|
if meth_name
|
171
|
-
if meth_name =~ /\A([^\.\#]+)[\.\#](.+)\z/
|
220
|
+
if meth_name =~ /\A([^\.\#]+)[\.\#](.+)\z/
|
172
221
|
context, meth_name = $1, $2
|
173
222
|
target = Pry.binding_for(target.eval(context))
|
174
223
|
end
|
175
224
|
else
|
176
225
|
meth_name = meth_name_from_binding(target)
|
177
226
|
end
|
178
|
-
|
227
|
+
|
179
228
|
if (meth = get_method_object(meth_name, target, opts.to_hash(true))).nil?
|
180
229
|
output.puts "Invalid method name: #{meth_name}. Type `gist-method --help` for help"
|
181
230
|
next
|
data/lib/pry/pry_class.rb
CHANGED
@@ -98,6 +98,11 @@ class Pry
|
|
98
98
|
# Set to true if the pry-doc extension is loaded.
|
99
99
|
# @return [Boolean]
|
100
100
|
attr_accessor :has_pry_doc
|
101
|
+
|
102
|
+
# The default editor to use. Defaults to $EDITOR or nano if
|
103
|
+
# $EDITOR is not defined.
|
104
|
+
# @return [String]
|
105
|
+
attr_accessor :editor
|
101
106
|
end
|
102
107
|
|
103
108
|
# Load the rc files given in the `Pry::RC_FILES` array.
|
@@ -201,6 +206,14 @@ class Pry
|
|
201
206
|
end
|
202
207
|
end
|
203
208
|
|
209
|
+
def self.default_editor_for_platform
|
210
|
+
if RUBY_PLATFORM =~ /mswin|mingw/
|
211
|
+
ENV['EDITOR'] ? ENV['EDITOR'] : "notepad"
|
212
|
+
else
|
213
|
+
ENV['EDITOR'] ? ENV['EDITOR'] : "nano"
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
204
217
|
# Set all the configurable options back to their default values
|
205
218
|
def self.reset_defaults
|
206
219
|
@input = Readline
|
@@ -216,6 +229,7 @@ class Pry
|
|
216
229
|
@should_load_rc = true
|
217
230
|
@rc_loaded = false
|
218
231
|
@cli = false
|
232
|
+
@editor = default_editor_for_platform
|
219
233
|
end
|
220
234
|
|
221
235
|
self.reset_defaults
|
data/lib/pry/pry_instance.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require "#{direc}/command_processor.rb"
|
1
|
+
require "pry/command_processor.rb"
|
4
2
|
|
5
3
|
class Pry
|
6
4
|
|
@@ -56,12 +54,7 @@ class Pry
|
|
56
54
|
# @return [Pry] The parent of the current Pry session.
|
57
55
|
def parent
|
58
56
|
idx = Pry.sessions.index(self)
|
59
|
-
|
60
|
-
if idx > 0
|
61
|
-
Pry.sessions[idx - 1]
|
62
|
-
else
|
63
|
-
nil
|
64
|
-
end
|
57
|
+
Pry.sessions[idx - 1] if idx > 0
|
65
58
|
end
|
66
59
|
|
67
60
|
# Execute the hook `hook_name`, if it is defined.
|
@@ -127,12 +120,7 @@ class Pry
|
|
127
120
|
end
|
128
121
|
|
129
122
|
return_value = repl_epilogue(target, nesting_level, break_data)
|
130
|
-
|
131
|
-
# if one was provided, return the return value
|
132
|
-
return return_value if return_value
|
133
|
-
|
134
|
-
# otherwise return the target_self
|
135
|
-
target_self
|
123
|
+
return_value || target_self
|
136
124
|
end
|
137
125
|
|
138
126
|
# Perform a read-eval-print.
|
@@ -358,10 +346,9 @@ class Pry
|
|
358
346
|
# valid_expression?("class Hello; end") #=> true
|
359
347
|
def valid_expression?(code)
|
360
348
|
RubyParser.new.parse(code)
|
349
|
+
true
|
361
350
|
rescue Racc::ParseError, SyntaxError
|
362
351
|
false
|
363
|
-
else
|
364
|
-
true
|
365
352
|
end
|
366
353
|
end
|
367
354
|
end
|
data/lib/pry/version.rb
CHANGED
data/test/test.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
direc = File.dirname(__FILE__)
|
2
2
|
|
3
|
+
$LOAD_PATH.unshift "#{direc}/../lib"
|
4
|
+
|
3
5
|
require 'rubygems'
|
4
6
|
require 'bacon'
|
5
|
-
require "
|
7
|
+
require "pry"
|
6
8
|
require "#{direc}/test_helper"
|
7
9
|
|
8
10
|
puts "Ruby Version #{RUBY_VERSION}"
|
@@ -73,7 +75,7 @@ describe Pry do
|
|
73
75
|
pry_tester.rep(o)
|
74
76
|
str_output.string.should == ""
|
75
77
|
end
|
76
|
-
|
78
|
+
|
77
79
|
|
78
80
|
it 'should suppress output if input ends in a ";" (multi-line)' do
|
79
81
|
o = Object.new
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: pry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.8.
|
5
|
+
version: 0.8.3
|
6
6
|
platform: i386-mswin32
|
7
7
|
authors:
|
8
8
|
- John Mair (banisterfiend)
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-04-
|
13
|
+
date: 2011-04-26 00:00:00 +12:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
requirements:
|
44
44
|
- - ">="
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: 1.5.
|
46
|
+
version: 1.5.3
|
47
47
|
type: :runtime
|
48
48
|
version_requirements: *id003
|
49
49
|
- !ruby/object:Gem::Dependency
|