pry 0.2.8 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +8 -4
- data/Rakefile +1 -1
- data/lib/pry.rb +20 -10
- data/lib/pry/output.rb +50 -33
- data/lib/pry/version.rb +1 -1
- metadata +12 -7
data/README.markdown
CHANGED
@@ -144,8 +144,8 @@ end.
|
|
144
144
|
* Pry sessions can nest arbitrarily deeply -- to go back one level of nesting type 'exit' or 'quit' or 'back'
|
145
145
|
* Use `_` to recover last result.
|
146
146
|
* Pry has multi-line support built in.
|
147
|
-
* Pry has unique commands not found in any other REPL: `show_method`,
|
148
|
-
`jump_to`, `ls`, `cd`
|
147
|
+
* Pry has unique commands not found in any other REPL: `show_method`, `show_doc`
|
148
|
+
`jump_to`, `ls`, `cd`, `cat`
|
149
149
|
* Pry gives good control over nested sessions (important when exploring complicated runtime state)
|
150
150
|
* Pry is not based on the IRB codebase.
|
151
151
|
* Pry uses [RubyParser](https://github.com/seattlerb/ruby_parser) to
|
@@ -202,11 +202,15 @@ If you want to access a method of the same name, prefix the invocation by whites
|
|
202
202
|
are nested sessions).
|
203
203
|
* `ls` returns a list of local variables and instance variables in the
|
204
204
|
current scope
|
205
|
+
* `cat <var>` calls `inspect` on `<var>`
|
205
206
|
* `cd <var>` starts a `Pry` session on the variable <var>. E.g `cd @x`
|
206
207
|
* `show_method <methname>` Displays the sourcecode for the method
|
207
208
|
<methname>. E.g `show_method hello`
|
208
|
-
* `
|
209
|
-
instance method <methname>. E.g `
|
209
|
+
* `show_imethod <methname>` Displays the sourcecode for the
|
210
|
+
instance method <methname>. E.g `show_imethod goodbye`
|
211
|
+
* `show_doc <methname>` Displays comments for `<methname>`
|
212
|
+
* `show_idoc <methname>` Displays comments for instance
|
213
|
+
method `<methname>`
|
210
214
|
* `exit_program` or `quit_program` will end the currently running
|
211
215
|
program.
|
212
216
|
* `nesting` shows Pry nesting information.
|
data/Rakefile
CHANGED
@@ -20,7 +20,7 @@ def apply_spec_defaults(s)
|
|
20
20
|
s.description = s.summary
|
21
21
|
s.require_path = 'lib'
|
22
22
|
s.add_dependency("ruby_parser",">=2.0.5")
|
23
|
-
s.add_dependency("method_source",">=0.
|
23
|
+
s.add_dependency("method_source",">=0.2.0")
|
24
24
|
s.homepage = "http://banisterfiend.wordpress.com"
|
25
25
|
s.has_rdoc = 'yard'
|
26
26
|
s.files = Dir["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c", "lib/**/*.rb",
|
data/lib/pry.rb
CHANGED
@@ -3,14 +3,13 @@
|
|
3
3
|
|
4
4
|
direc = File.dirname(__FILE__)
|
5
5
|
|
6
|
-
require
|
7
|
-
require 'method_source'
|
6
|
+
require "method_source"
|
8
7
|
require "#{direc}/pry/version"
|
9
8
|
require "#{direc}/pry/input"
|
10
9
|
require "#{direc}/pry/output"
|
11
10
|
|
12
11
|
class Pry
|
13
|
-
def self.start(target)
|
12
|
+
def self.start(target=TOPLEVEL_BINDING)
|
14
13
|
new.repl(target)
|
15
14
|
end
|
16
15
|
|
@@ -158,18 +157,32 @@ class Pry
|
|
158
157
|
when "ls"
|
159
158
|
output.ls(target)
|
160
159
|
eval_string.clear
|
160
|
+
when /^cat\s+(.+)/
|
161
|
+
var = $~.captures.first
|
162
|
+
output.cat(target, var)
|
163
|
+
eval_string.clear
|
161
164
|
when /^cd\s+(.+)/
|
162
165
|
obj = $~.captures.first
|
163
166
|
target.eval("#{obj}.pry")
|
164
167
|
eval_string.clear
|
168
|
+
when /^show_doc\s*(.+)/
|
169
|
+
meth_name = ($~.captures).first
|
170
|
+
doc = target.eval("method(:#{meth_name})").comment
|
171
|
+
output.show_doc doc
|
172
|
+
eval_string.clear
|
173
|
+
when /^show_idoc\s*(.+)/
|
174
|
+
meth_name = ($~.captures).first
|
175
|
+
doc = target.eval("instance_method(:#{meth_name})").comment
|
176
|
+
output.show_doc doc
|
177
|
+
eval_string.clear
|
165
178
|
when /^show_method\s*(.+)/
|
166
179
|
meth_name = ($~.captures).first
|
167
|
-
code =
|
180
|
+
code = target.eval("method(:#{meth_name})").source
|
168
181
|
output.show_method code
|
169
182
|
eval_string.clear
|
170
|
-
when /^show_instance_method\s*(.+)/
|
183
|
+
when /^show_instance_method\s*(.+)/, /^show_imethod\s*(.+)/
|
171
184
|
meth_name = ($~.captures).first
|
172
|
-
code =
|
185
|
+
code = target.eval("instance_method(:#{meth_name})").source
|
173
186
|
output.show_method code
|
174
187
|
eval_string.clear
|
175
188
|
when /^jump_to\s*(\d*)/
|
@@ -190,10 +203,6 @@ class Pry
|
|
190
203
|
end
|
191
204
|
end
|
192
205
|
|
193
|
-
def get_method_source(target, meth_name, kind)
|
194
|
-
target.eval("#{kind}(:#{meth_name}).source")
|
195
|
-
end
|
196
|
-
|
197
206
|
def prompt(eval_string, target, nest)
|
198
207
|
target_self = target.eval('self')
|
199
208
|
|
@@ -212,6 +221,7 @@ class Pry
|
|
212
221
|
end
|
213
222
|
|
214
223
|
else
|
224
|
+
require 'ruby_parser'
|
215
225
|
|
216
226
|
def valid_expression?(code)
|
217
227
|
RubyParser.new.parse(code)
|
data/lib/pry/output.rb
CHANGED
@@ -1,79 +1,96 @@
|
|
1
1
|
class Pry
|
2
2
|
class Output
|
3
|
+
attr_reader :out
|
4
|
+
|
5
|
+
def initialize(out=STDOUT)
|
6
|
+
@out = out
|
7
|
+
end
|
8
|
+
|
3
9
|
def refresh
|
4
|
-
puts "Refreshed REPL"
|
10
|
+
out.puts "Refreshed REPL"
|
5
11
|
end
|
6
12
|
|
7
13
|
def session_start(obj)
|
8
|
-
puts "Beginning Pry session for #{Pry.view(obj)}"
|
14
|
+
out.puts "Beginning Pry session for #{Pry.view(obj)}"
|
9
15
|
end
|
10
16
|
|
11
17
|
def session_end(obj)
|
12
|
-
puts "Ending Pry session for #{Pry.view(obj)}"
|
18
|
+
out.puts "Ending Pry session for #{Pry.view(obj)}"
|
13
19
|
end
|
14
20
|
|
15
21
|
# the print component of READ-EVAL-PRINT-LOOP
|
16
22
|
def print(value)
|
17
23
|
case value
|
18
24
|
when Exception
|
19
|
-
puts "#{value.class}: #{value.message}"
|
25
|
+
out.puts "#{value.class}: #{value.message}"
|
20
26
|
else
|
21
|
-
puts "=> #{Pry.view(value)}"
|
27
|
+
out.puts "=> #{Pry.view(value)}"
|
22
28
|
end
|
23
29
|
end
|
24
30
|
|
25
31
|
def show_help
|
26
|
-
puts "Command list:"
|
27
|
-
puts "--"
|
28
|
-
puts "help This menu"
|
29
|
-
puts "status Show status information"
|
30
|
-
puts "! Refresh the REPL"
|
31
|
-
puts "nesting Show nesting information"
|
32
|
-
puts "ls Show the list of variables in the current scope"
|
33
|
-
puts "
|
34
|
-
puts "
|
35
|
-
puts "
|
36
|
-
puts "
|
37
|
-
puts "
|
38
|
-
puts "
|
39
|
-
puts "
|
32
|
+
out.puts "Command list:"
|
33
|
+
out.puts "--"
|
34
|
+
out.puts "help This menu"
|
35
|
+
out.puts "status Show status information"
|
36
|
+
out.puts "! Refresh the REPL"
|
37
|
+
out.puts "nesting Show nesting information"
|
38
|
+
out.puts "ls Show the list of variables in the current scope"
|
39
|
+
out.puts "cat <var> Show output of <var>.inspect"
|
40
|
+
out.puts "cd <var> Start a Pry session on <var> (use `cd ..` to go back)"
|
41
|
+
out.puts "show_method <methname> Show the sourcecode for the method <methname>"
|
42
|
+
out.puts "show_imethod <methname> Show the sourcecode for the instance method <method_name>"
|
43
|
+
out.puts "show_doc <methname> Show the comments above <methname>"
|
44
|
+
out.puts "show_idoc <methname> Show the comments above instance method <methname>"
|
45
|
+
out.puts "exit/quit/back End the current Pry session"
|
46
|
+
out.puts "exit_all End all nested Pry sessions"
|
47
|
+
out.puts "exit_program/quit_program End the current program"
|
48
|
+
out.puts "jump_to <level> Jump to a Pry session further up the stack, exiting all sessions below"
|
40
49
|
end
|
41
50
|
|
42
51
|
def show_nesting(nesting)
|
43
|
-
puts "Nesting status:"
|
44
|
-
puts "--"
|
52
|
+
out.puts "Nesting status:"
|
53
|
+
out.puts "--"
|
45
54
|
nesting.each do |level, obj|
|
46
55
|
if level == 0
|
47
|
-
puts "#{level}. #{Pry.view(obj)} (Pry top level)"
|
56
|
+
out.puts "#{level}. #{Pry.view(obj)} (Pry top level)"
|
48
57
|
else
|
49
|
-
puts "#{level}. #{Pry.view(obj)}"
|
58
|
+
out.puts "#{level}. #{Pry.view(obj)}"
|
50
59
|
end
|
51
60
|
end
|
52
61
|
end
|
53
62
|
|
54
63
|
def show_status(nesting, target)
|
55
|
-
puts "Status:"
|
56
|
-
puts "--"
|
57
|
-
puts "Receiver: #{Pry.view(target.eval('self'))}"
|
58
|
-
puts "Nesting level: #{nesting.level}"
|
59
|
-
puts "Local variables: #{target.eval('Pry.view(local_variables)')}"
|
60
|
-
puts "Last result: #{Pry.view(Pry.last_result)}"
|
64
|
+
out.puts "Status:"
|
65
|
+
out.puts "--"
|
66
|
+
out.puts "Receiver: #{Pry.view(target.eval('self'))}"
|
67
|
+
out.puts "Nesting level: #{nesting.level}"
|
68
|
+
out.puts "Local variables: #{target.eval('Pry.view(local_variables)')}"
|
69
|
+
out.puts "Last result: #{Pry.view(Pry.last_result)}"
|
61
70
|
end
|
62
71
|
|
63
72
|
def ls(target)
|
64
|
-
puts "#{target.eval('Pry.view(local_variables + instance_variables)')}"
|
73
|
+
out.puts "#{target.eval('Pry.view(local_variables + instance_variables)')}"
|
74
|
+
end
|
75
|
+
|
76
|
+
def cat(target, var)
|
77
|
+
out.puts target.eval("#{var}.inspect")
|
65
78
|
end
|
66
79
|
|
67
80
|
def show_method(code)
|
68
|
-
code
|
81
|
+
out.puts code
|
82
|
+
end
|
83
|
+
|
84
|
+
def show_doc(doc)
|
85
|
+
out.puts doc
|
69
86
|
end
|
70
87
|
|
71
88
|
def warn_already_at_level(nesting_level)
|
72
|
-
puts "Already at nesting level #{nesting_level}"
|
89
|
+
out.puts "Already at nesting level #{nesting_level}"
|
73
90
|
end
|
74
91
|
|
75
92
|
def err_invalid_nest_level(nest_level, max_nest_level)
|
76
|
-
puts "Invalid nest level. Must be between 0 and #{max_nest_level}. Got #{nest_level}."
|
93
|
+
out.puts "Invalid nest level. Must be between 0 and #{max_nest_level}. Got #{nest_level}."
|
77
94
|
end
|
78
95
|
|
79
96
|
def exit() end
|
data/lib/pry/version.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- John Mair (banisterfiend)
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-12-
|
18
|
+
date: 2010-12-19 00:00:00 +13:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
@@ -25,6 +26,7 @@ dependencies:
|
|
25
26
|
requirements:
|
26
27
|
- - ">="
|
27
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 5
|
28
30
|
segments:
|
29
31
|
- 2
|
30
32
|
- 0
|
@@ -40,11 +42,12 @@ dependencies:
|
|
40
42
|
requirements:
|
41
43
|
- - ">="
|
42
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 23
|
43
46
|
segments:
|
44
47
|
- 0
|
45
|
-
-
|
46
|
-
-
|
47
|
-
version: 0.
|
48
|
+
- 2
|
49
|
+
- 0
|
50
|
+
version: 0.2.0
|
48
51
|
type: :runtime
|
49
52
|
version_requirements: *id002
|
50
53
|
description: attach an irb-like session to any object at runtime
|
@@ -77,6 +80,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
80
|
requirements:
|
78
81
|
- - ">="
|
79
82
|
- !ruby/object:Gem::Version
|
83
|
+
hash: 3
|
80
84
|
segments:
|
81
85
|
- 0
|
82
86
|
version: "0"
|
@@ -85,6 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
89
|
requirements:
|
86
90
|
- - ">="
|
87
91
|
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
88
93
|
segments:
|
89
94
|
- 0
|
90
95
|
version: "0"
|