pry 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,9 +16,10 @@ It is not based on the IRB codebase, and implements some unique REPL
16
16
  commands such as `show_method` and `show_doc`
17
17
 
18
18
  Pry is also fairly flexible and allows significant user
19
- customization. It is trivial to set it to read from any
20
- object that has a `readline` method and write to any object that has a
21
- `puts` method - many other aspects of Pry are also configurable.
19
+ [customization](http://rdoc.info/github/banister/pry/master/file/wiki/Customizing-pry.md). It
20
+ is trivial to set it to read from any object that has a `readline` method and write to any object that has a
21
+ `puts` method - many other aspects of Pry are also configurable making
22
+ it a good choice for implementing custom shells.
22
23
 
23
24
  * Install the [gem](https://rubygems.org/gems/pry): `gem install pry`
24
25
  * Read the [documentation](http://rdoc.info/github/banister/pry/master/file/README.markdown)
@@ -262,6 +263,23 @@ If you want to access a method of the same name, prefix the invocation by whites
262
263
  current one with `obj` as the receiver of the new session. Very useful
263
264
  when exploring large or complicated runtime state.
264
265
 
266
+ Bindings and objects
267
+ --------------------
268
+
269
+ Pry ultimately operates on `Binding` objects. If you invoke Pry with a
270
+ Binding object it uses that Binding. If you invoke Pry with anything
271
+ other than a `Binding`, Pry will generate a Binding for that
272
+ object and use that.
273
+
274
+ If you want to open a Pry session on the current context and capture
275
+ the locals you should use: `binding.pry`. If you do not care about
276
+ capturing the locals you can simply use `pry` (which will generate a
277
+ fresh `Binding` for the receiver).
278
+
279
+ Top-level is a special case; you can start a Pry session on top-level
280
+ *and* capture locals by simply using: `pry`. This is because Pry
281
+ automatically uses `TOPLEVEL_BINDING` for the top-level object (main).
282
+
265
283
  Example Programs
266
284
  ----------------
267
285
 
@@ -16,7 +16,7 @@ class MyCommands < Pry::CommandBase
16
16
  # bring in just the status command from Pry::Commands
17
17
  import_from Pry::Commands, "status"
18
18
 
19
- # analagy to Ruby's native alias_method idiom for decorating a method
19
+ # analogy to Ruby's native alias_method idiom for decorating a method
20
20
  alias_command "old_status", "status", ""
21
21
 
22
22
  # Invoke one command from within another using `run`
@@ -87,9 +87,11 @@ class Pry
87
87
  # Create an alias for a command.
88
88
  # @param [String] new_command The alias name.
89
89
  # @param [String] orig_command The original command name.
90
+ # @param [String] desc The optional description.
90
91
  # @example
91
92
  # class MyCommands < Pry::CommandBase
92
93
  # alias_command "help_alias", "help"
94
+ # end
93
95
  def alias_command(new_command_name, orig_command_name, desc=nil)
94
96
  commands[new_command_name] = commands[orig_command_name].dup
95
97
  commands[new_command_name][:description] = desc if desc
@@ -51,8 +51,18 @@ class Pry
51
51
  throw(:breakout, 0)
52
52
  end
53
53
 
54
- command "ls", "Show the list of vars in the current scope." do
55
- output.puts "#{Pry.view(target.eval('local_variables + instance_variables'))}"
54
+ command "ls", "Show the list of vars in the current scope. Use -c to include constants." do |arg|
55
+ with_constants = (arg == "-c")
56
+ target_self = target.eval('self')
57
+
58
+ case target_self
59
+ when Module
60
+ c = with_constants ? target_self.constants : []
61
+ output.puts "#{Pry.view(target.eval("local_variables + instance_variables + #{c}"))}"
62
+ else
63
+ c = with_constants ? target_self.class.constants : []
64
+ output.puts "#{Pry.view(target.eval("local_variables + instance_variables + #{c}"))}"
65
+ end
56
66
  end
57
67
 
58
68
  command "cat", "Show output of <var>.inspect." do |obj|
@@ -3,10 +3,10 @@ require 'readline'
3
3
  class Pry
4
4
 
5
5
  # The list of configuration options.
6
- ConfigOptions = [:input, :output, :commands, :print,
6
+ CONFIG_OPTIONS = [:input, :output, :commands, :print,
7
7
  :prompt, :hooks]
8
8
 
9
- attr_accessor *ConfigOptions
9
+ attr_accessor *CONFIG_OPTIONS
10
10
 
11
11
  # Create a new `Pry` object.
12
12
  # @param [Hash] options The optional configuration parameters.
@@ -21,12 +21,11 @@ class Pry
21
21
  # component of the REPL. (see print.rb)
22
22
  def initialize(options={})
23
23
 
24
- h = {}
25
- ConfigOptions.each { |v| h[v] = Pry.send(v) }
26
- default_options = h
24
+ default_options = {}
25
+ CONFIG_OPTIONS.each { |v| default_options[v] = Pry.send(v) }
27
26
  default_options.merge!(options)
28
27
 
29
- ConfigOptions.each do |key|
28
+ CONFIG_OPTIONS.each do |key|
30
29
  instance_variable_set("@#{key}", default_options[key])
31
30
  end
32
31
  end
@@ -1,3 +1,3 @@
1
1
  class Pry
2
- VERSION = "0.4.5"
2
+ VERSION = "0.4.6"
3
3
  end
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: 3
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 4
8
- - 5
9
- version: 0.4.5
9
+ - 6
10
+ version: 0.4.6
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: 2011-01-27 00:00:00 +13:00
18
+ date: 2011-02-02 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,6 +42,7 @@ dependencies:
40
42
  requirements:
41
43
  - - ">="
42
44
  - !ruby/object:Gem::Version
45
+ hash: 23
43
46
  segments:
44
47
  - 0
45
48
  - 2
@@ -55,6 +58,7 @@ dependencies:
55
58
  requirements:
56
59
  - - ">="
57
60
  - !ruby/object:Gem::Version
61
+ hash: 19
58
62
  segments:
59
63
  - 1
60
64
  - 1
@@ -112,6 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
116
  requirements:
113
117
  - - ">="
114
118
  - !ruby/object:Gem::Version
119
+ hash: 3
115
120
  segments:
116
121
  - 0
117
122
  version: "0"
@@ -120,6 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
125
  requirements:
121
126
  - - ">="
122
127
  - !ruby/object:Gem::Version
128
+ hash: 3
123
129
  segments:
124
130
  - 0
125
131
  version: "0"