pry 0.6.7 → 0.6.8

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ 6/3/2011 version 0.6.8
2
+ * add whereami command, a la the `ir_b` gem
3
+ * make whereami run at the start of every session
4
+ * make .pryrc be loaded by run-time pry sessions
5
+
1
6
  4/3/2011 version 0.6.7
2
7
  * color support
3
8
  * --simple-prompt for pry commandline
data/LICENSE CHANGED
@@ -1,25 +1,25 @@
1
- License
2
- -------
3
-
4
- (The MIT License)
5
-
6
- Copyright (c) 2011 John Mair (banisterfiend)
7
-
8
- Permission is hereby granted, free of charge, to any person obtaining
9
- a copy of this software and associated documentation files (the
10
- 'Software'), to deal in the Software without restriction, including
11
- without limitation the rights to use, copy, modify, merge, publish,
12
- distribute, sublicense, and/or sell copies of the Software, and to
13
- permit persons to whom the Software is furnished to do so, subject to
14
- the following conditions:
15
-
16
- The above copyright notice and this permission notice shall be
17
- included in all copies or substantial portions of the Software.
18
-
19
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
20
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ License
2
+ -------
3
+
4
+ (The MIT License)
5
+
6
+ Copyright (c) 2011 John Mair (banisterfiend)
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining
9
+ a copy of this software and associated documentation files (the
10
+ 'Software'), to deal in the Software without restriction, including
11
+ without limitation the rights to use, copy, modify, merge, publish,
12
+ distribute, sublicense, and/or sell copies of the Software, and to
13
+ permit persons to whom the Software is furnished to do so, subject to
14
+ the following conditions:
15
+
16
+ The above copyright notice and this permission notice shall be
17
+ included in all copies or substantial portions of the Software.
18
+
19
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
20
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -42,7 +42,7 @@ Example: Interacting with an object at runtime
42
42
 
43
43
  With the `Object#pry` method we can pry (open an irb-like session) on
44
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.
45
+ an instance variable. The current thread is taken over by the Pry REPL loop for the duration of the session.
46
46
 
47
47
  require 'pry'
48
48
 
@@ -164,7 +164,7 @@ end.
164
164
 
165
165
  * Pry can be invoked at any time and on any object in the running program.
166
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.
167
+ * Pry comes with syntax highlighting on by default just use the `toggle-color` command to use it.
168
168
  * Use `_` to recover last result.
169
169
  * Use `_pry_` to reference the Pry instance managing the current session.
170
170
  * Pry supports tab completion.
@@ -240,6 +240,7 @@ If you want to access a method of the same name, prefix the invocation by whites
240
240
  getting you out of a situation where the parsing process
241
241
  goes wrong and you get stuck in an endless read loop.
242
242
  * `status` shows status information about the current session.
243
+ * `whereami` shows the code context of the session.
243
244
  * `version` Show Pry version information
244
245
  * `help` shows the list of session commands with brief explanations.
245
246
  * `toggle-color` turns on and off syntax highlighting.
@@ -265,6 +266,14 @@ If you want to access a method of the same name, prefix the invocation by whites
265
266
  current one with `obj` as the receiver of the new session. Very useful
266
267
  when exploring large or complicated runtime state.
267
268
 
269
+ Syntax Highlighting
270
+ --------------------
271
+
272
+ Syntax highlighting is on by default in Pry. You can toggle it on and
273
+ off in a session by using the `toggle-color` command. Alternatively,
274
+ you can turn it off permanently by putting the line `Pry.color =
275
+ false` in your `~/.pryrc` file.
276
+
268
277
  Bindings and objects
269
278
  --------------------
270
279
 
data/Rakefile CHANGED
@@ -26,7 +26,7 @@ def apply_spec_defaults(s)
26
26
  s.has_rdoc = 'yard'
27
27
  s.executables = ["pry"]
28
28
  s.files = Dir["ext/**/extconf.rb", "ext/**/*.h", "ext/**/*.c", "lib/**/*.rb", "examples/**/*.rb",
29
- "test/*.rb", "CHANGELOG", "LICENSE", "README.markdown", "Rakefile", ".gemtest"]
29
+ "test/*.rb", "test/testrc", "CHANGELOG", "LICENSE", "README.markdown", "Rakefile", ".gemtest"]
30
30
  end
31
31
 
32
32
  task :test do
data/bin/pry CHANGED
@@ -35,8 +35,8 @@ See: `https://github.com/banister` for more information.
35
35
  options[:loadrc] = false
36
36
  end
37
37
 
38
- opts.on("--color", "Start session with syntax highlighting on.") do
39
- Pry.color = true
38
+ opts.on("--no-color", "Start session without syntax highlighting.") do
39
+ Pry.color = false
40
40
  end
41
41
 
42
42
  opts.on("--simple-prompt", "Simple prompt mode.") do
@@ -65,10 +65,11 @@ See: `https://github.com/banister` for more information.
65
65
  end
66
66
  end.parse!
67
67
 
68
- rcpath = File.expand_path("~/.pryrc")
68
+ # invoked via cli
69
+ Pry.cli = true
69
70
 
70
71
  # load ~/.pryrc, if not suppressed with -f option
71
- load rcpath if File.exists?(rcpath) && options[:loadrc]
72
+ Pry.should_load_rc = false if !options[:loadrc]
72
73
 
73
74
  # create the actual context
74
75
  context = Pry.binding_for(eval(options[:context_string]))
@@ -1,17 +1,17 @@
1
- direc = File.dirname(__FILE__)
2
-
3
- require 'rubygems'
4
- require "#{direc}/../lib/pry"
5
-
6
- # define a local.
7
- a = "a local variable"
8
-
9
- # defing a top-level method.
10
- def hello
11
- puts "hello world!"
12
- end
13
-
14
- # Start pry session at top-level.
15
- # The local variable `a` and the `hello` method will
16
- # be accessible.
17
- pry
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require "#{direc}/../lib/pry"
5
+
6
+ # define a local.
7
+ a = "a local variable"
8
+
9
+ # defing a top-level method.
10
+ def hello
11
+ puts "hello world!"
12
+ end
13
+
14
+ # Start pry session at top-level.
15
+ # The local variable `a` and the `hello` method will
16
+ # be accessible.
17
+ pry
@@ -1,35 +1,35 @@
1
- direc = File.dirname(__FILE__)
2
-
3
- require 'rubygems'
4
- require "#{direc}/../lib/pry"
5
-
6
- # Inherit standard command set, but tweak them by importing some and
7
- # overriding others.
8
- # Illustrates use of `command`, `run`, and `import_from` commands.
9
- class MyCommands < Pry::CommandBase
10
-
11
- # Override ls command
12
- command "ls", "An unhelpful ls" do
13
- output.puts "No, i refuse to display any useful information."
14
- end
15
-
16
- # bring in just the status command from Pry::Commands
17
- import_from Pry::Commands, "status"
18
-
19
- # analogy to Ruby's native alias_method idiom for decorating a method
20
- alias_command "old_status", "status", ""
21
-
22
- # Invoke one command from within another using `run`
23
- command "status", "Modified status." do |x|
24
- output.puts "About to show status, are you ready?"
25
- run "old_status", x
26
- output.puts "Finished showing status."
27
- end
28
-
29
- # bring in a few other commands
30
- import_from Pry::Commands, "quit", "show-method"
31
- end
32
-
33
- # Start a Pry session using the commands defined in MyCommands
34
- # Type 'help' in Pry to get a list of the commands and their descriptions
35
- Pry.start(TOPLEVEL_BINDING, :commands => MyCommands)
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require "#{direc}/../lib/pry"
5
+
6
+ # Inherit standard command set, but tweak them by importing some and
7
+ # overriding others.
8
+ # Illustrates use of `command`, `run`, and `import_from` commands.
9
+ class MyCommands < Pry::CommandBase
10
+
11
+ # Override ls command
12
+ command "ls", "An unhelpful ls" do
13
+ output.puts "No, i refuse to display any useful information."
14
+ end
15
+
16
+ # bring in just the status command from Pry::Commands
17
+ import_from Pry::Commands, "status"
18
+
19
+ # analogy to Ruby's native alias_method idiom for decorating a method
20
+ alias_command "old_status", "status", ""
21
+
22
+ # Invoke one command from within another using `run`
23
+ command "status", "Modified status." do |x|
24
+ output.puts "About to show status, are you ready?"
25
+ run "old_status", x
26
+ output.puts "Finished showing status."
27
+ end
28
+
29
+ # bring in a few other commands
30
+ import_from Pry::Commands, "quit", "show-method"
31
+ end
32
+
33
+ # Start a Pry session using the commands defined in MyCommands
34
+ # Type 'help' in Pry to get a list of the commands and their descriptions
35
+ Pry.start(TOPLEVEL_BINDING, :commands => MyCommands)
@@ -1,39 +1,39 @@
1
- direc = File.dirname(__FILE__)
2
-
3
- require 'rubygems'
4
- require "#{direc}/../lib/pry"
5
-
6
- class MathCommands < Pry::CommandBase
7
- command "greet", "Greet a person, e.g: greet john" do |name|
8
- output.puts "Good afternoon #{name.capitalize}! Do you like Math?"
9
- end
10
-
11
- command "add", "Add a list of numbers together, e.g: add 1 2 3 4" do |*args|
12
- output.puts "Total: #{args.map(&:to_f).inject(&:+)}"
13
- end
14
-
15
- command "multiply", "Multiply a list of numbers together, e.g: multiply 1 2 3 4" do |*args|
16
- output.puts "Total: #{args.map(&:to_f).inject(&:*)}"
17
- end
18
-
19
- # Explicitly giving a description of "" to prevent command being
20
- # displayed in 'help'
21
- command "exit", "" do
22
- throw :breakout, 0
23
- end
24
-
25
- # Bring in the "!" method from Pry::Commands
26
- import_from Pry::Commands, "!"
27
- end
28
-
29
- # Since we provide math commands, let's have mathematical
30
- # before_session and after_session hooks, and a mathematical prompt
31
- math_prompt = [proc { "math> " }, proc { "math* " }]
32
- math_hooks = {
33
- :before_session => proc { |output, *| output.puts "Welcome! Let's do some math! Type 'help' for a list of commands." },
34
- :after_session => proc { |output, *| output.puts "Goodbye!" }
35
- }
36
-
37
- # Start a Pry session using the commands defined in MyCommands
38
- # Type 'help' in Pry to get a list of the commands and their descriptions
39
- Pry.start(TOPLEVEL_BINDING, :commands => MathCommands, :prompt => math_prompt, :hooks => math_hooks)
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require "#{direc}/../lib/pry"
5
+
6
+ class MathCommands < Pry::CommandBase
7
+ command "greet", "Greet a person, e.g: greet john" do |name|
8
+ output.puts "Good afternoon #{name.capitalize}! Do you like Math?"
9
+ end
10
+
11
+ command "add", "Add a list of numbers together, e.g: add 1 2 3 4" do |*args|
12
+ output.puts "Total: #{args.map(&:to_f).inject(&:+)}"
13
+ end
14
+
15
+ command "multiply", "Multiply a list of numbers together, e.g: multiply 1 2 3 4" do |*args|
16
+ output.puts "Total: #{args.map(&:to_f).inject(&:*)}"
17
+ end
18
+
19
+ # Explicitly giving a description of "" to prevent command being
20
+ # displayed in 'help'
21
+ command "exit", "" do
22
+ throw :breakout, 0
23
+ end
24
+
25
+ # Bring in the "!" method from Pry::Commands
26
+ import_from Pry::Commands, "!"
27
+ end
28
+
29
+ # Since we provide math commands, let's have mathematical
30
+ # before_session and after_session hooks, and a mathematical prompt
31
+ math_prompt = [proc { "math> " }, proc { "math* " }]
32
+ math_hooks = {
33
+ :before_session => proc { |output, *| output.puts "Welcome! Let's do some math! Type 'help' for a list of commands." },
34
+ :after_session => proc { |output, *| output.puts "Goodbye!" }
35
+ }
36
+
37
+ # Start a Pry session using the commands defined in MyCommands
38
+ # Type 'help' in Pry to get a list of the commands and their descriptions
39
+ Pry.start(TOPLEVEL_BINDING, :commands => MathCommands, :prompt => math_prompt, :hooks => math_hooks)
@@ -1,12 +1,12 @@
1
- direc = File.dirname(__FILE__)
2
-
3
- require 'rubygems'
4
- require "#{direc}/../lib/pry"
5
-
6
- my_hooks = {
7
- :before_session => proc { |out, obj| out.puts "Opening #{obj}." },
8
- :after_session => proc { |out, obj| out.puts "Closing #{obj}." }
9
- }
10
-
11
- # Start a Pry session using the hooks hash defined in my_hooks
12
- Pry.start(TOPLEVEL_BINDING, :hooks => my_hooks)
1
+ direc = File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ require "#{direc}/../lib/pry"
5
+
6
+ my_hooks = {
7
+ :before_session => proc { |out, target| out.puts "Opening #{target.eval('self')}." },
8
+ :after_session => proc { |out, target| out.puts "Closing #{target.eval('self')}." }
9
+ }
10
+
11
+ # Start a Pry session using the hooks hash defined in my_hooks
12
+ Pry.start(TOPLEVEL_BINDING, :hooks => my_hooks)
@@ -1,71 +1,71 @@
1
- # Note: this requires you to have Gosu and TexPlay installed.
2
- # `gem install gosu`
3
- # `gem install texplay`
4
- #
5
- # Extra instructions for installing Gosu on Linux can be found here:
6
- # http://code.google.com/p/gosu/wiki/GettingStartedOnLinux
7
- #
8
- # Instructions for using TexPlay can be found here:
9
- # http://banisterfiend.wordpress.com/2008/08/23/texplay-an-image-manipulation-tool-for-ruby-and-gosu/
10
- #
11
- # Have fun! :)
12
-
13
- direc = File.dirname(__FILE__)
14
-
15
- require 'rubygems'
16
- require "texplay"
17
- require "#{direc}/../lib/pry"
18
-
19
- WIDTH = 640
20
- HEIGHT = 480
21
-
22
- IMAGE_PROMPT = [ proc { "(image edit)> " }, proc { "(image edit)* " } ]
23
-
24
- class ImageCommands < Pry::CommandBase
25
- command "drawing_methods", "Show a list of TexPlay methods" do
26
- output.puts "#{Pry.view(TexPlay.public_instance_methods)}"
27
- end
28
-
29
- command "exit", "Exit the program." do
30
- output.puts "Thanks for dropping by!"
31
- exit
32
- end
33
-
34
- import_from Pry::Commands, "ls", "!"
35
- end
36
-
37
- class WinClass < Gosu::Window
38
-
39
- def initialize
40
- super(WIDTH, HEIGHT, false)
41
- @img = TexPlay.create_image(self, 200, 200).clear :color => :black
42
- @img.rect 0, 0, @img.width - 1, @img.height - 1
43
-
44
- @binding = Pry.binding_for(@img)
45
-
46
- @pry_instance = Pry.new(:commands => ImageCommands, :prompt => IMAGE_PROMPT)
47
- end
48
-
49
- def draw
50
- @img.draw_rot(WIDTH / 2, HEIGHT / 2, 1, 0, 0.5, 0.5)
51
- end
52
-
53
- def update
54
- exit if button_down?(Gosu::KbEscape)
55
-
56
- # We do not want a REPL session as the loop prevents the image
57
- # being updated; instead we do a REP session, and let the image
58
- # update each time the user presses enter. We maintain the same
59
- # binding object to keep locals between calls to `Pry#rep()`
60
- @pry_instance.rep(@binding)
61
- end
62
- end
63
-
64
- puts "Welcome to ImageEdit; type `help` for a list of commands and `drawing_methods` for a list of drawing methods available."
65
- puts "--"
66
- puts "Example: Try typing 'circle width/2, height/2, 95, :color => :blue, :fill => true'"
67
- puts "If you want to save your image, type: save(\"img.png\")"
68
-
69
- w = WinClass.new
70
- w.show
71
-
1
+ # Note: this requires you to have Gosu and TexPlay installed.
2
+ # `gem install gosu`
3
+ # `gem install texplay`
4
+ #
5
+ # Extra instructions for installing Gosu on Linux can be found here:
6
+ # http://code.google.com/p/gosu/wiki/GettingStartedOnLinux
7
+ #
8
+ # Instructions for using TexPlay can be found here:
9
+ # http://banisterfiend.wordpress.com/2008/08/23/texplay-an-image-manipulation-tool-for-ruby-and-gosu/
10
+ #
11
+ # Have fun! :)
12
+
13
+ direc = File.dirname(__FILE__)
14
+
15
+ require 'rubygems'
16
+ require "texplay"
17
+ require "#{direc}/../lib/pry"
18
+
19
+ WIDTH = 640
20
+ HEIGHT = 480
21
+
22
+ IMAGE_PROMPT = [ proc { "(image edit)> " }, proc { "(image edit)* " } ]
23
+
24
+ class ImageCommands < Pry::CommandBase
25
+ command "drawing_methods", "Show a list of TexPlay methods" do
26
+ output.puts "#{Pry.view(TexPlay.public_instance_methods)}"
27
+ end
28
+
29
+ command "exit", "Exit the program." do
30
+ output.puts "Thanks for dropping by!"
31
+ exit
32
+ end
33
+
34
+ import_from Pry::Commands, "ls", "!"
35
+ end
36
+
37
+ class WinClass < Gosu::Window
38
+
39
+ def initialize
40
+ super(WIDTH, HEIGHT, false)
41
+ @img = TexPlay.create_image(self, 200, 200).clear :color => :black
42
+ @img.rect 0, 0, @img.width - 1, @img.height - 1
43
+
44
+ @binding = Pry.binding_for(@img)
45
+
46
+ @pry_instance = Pry.new(:commands => ImageCommands, :prompt => IMAGE_PROMPT)
47
+ end
48
+
49
+ def draw
50
+ @img.draw_rot(WIDTH / 2, HEIGHT / 2, 1, 0, 0.5, 0.5)
51
+ end
52
+
53
+ def update
54
+ exit if button_down?(Gosu::KbEscape)
55
+
56
+ # We do not want a REPL session as the loop prevents the image
57
+ # being updated; instead we do a REP session, and let the image
58
+ # update each time the user presses enter. We maintain the same
59
+ # binding object to keep locals between calls to `Pry#rep()`
60
+ @pry_instance.rep(@binding)
61
+ end
62
+ end
63
+
64
+ puts "Welcome to ImageEdit; type `help` for a list of commands and `drawing_methods` for a list of drawing methods available."
65
+ puts "--"
66
+ puts "Example: Try typing 'circle width/2, height/2, 95, :color => :blue, :fill => true'"
67
+ puts "If you want to save your image, type: save(\"img.png\")"
68
+
69
+ w = WinClass.new
70
+ w.show
71
+