pry 0.10.0.pre2-universal-mingw32

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.
Files changed (131) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +702 -0
  3. data/LICENSE +25 -0
  4. data/README.md +406 -0
  5. data/bin/pry +16 -0
  6. data/lib/pry.rb +161 -0
  7. data/lib/pry/cli.rb +220 -0
  8. data/lib/pry/code.rb +346 -0
  9. data/lib/pry/code/code_file.rb +103 -0
  10. data/lib/pry/code/code_range.rb +71 -0
  11. data/lib/pry/code/loc.rb +92 -0
  12. data/lib/pry/code_object.rb +172 -0
  13. data/lib/pry/color_printer.rb +55 -0
  14. data/lib/pry/command.rb +692 -0
  15. data/lib/pry/command_set.rb +443 -0
  16. data/lib/pry/commands.rb +6 -0
  17. data/lib/pry/commands/amend_line.rb +99 -0
  18. data/lib/pry/commands/bang.rb +20 -0
  19. data/lib/pry/commands/bang_pry.rb +17 -0
  20. data/lib/pry/commands/cat.rb +62 -0
  21. data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
  22. data/lib/pry/commands/cat/exception_formatter.rb +77 -0
  23. data/lib/pry/commands/cat/file_formatter.rb +67 -0
  24. data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
  25. data/lib/pry/commands/cd.rb +41 -0
  26. data/lib/pry/commands/change_inspector.rb +27 -0
  27. data/lib/pry/commands/change_prompt.rb +26 -0
  28. data/lib/pry/commands/code_collector.rb +165 -0
  29. data/lib/pry/commands/disable_pry.rb +27 -0
  30. data/lib/pry/commands/disabled_commands.rb +2 -0
  31. data/lib/pry/commands/easter_eggs.rb +112 -0
  32. data/lib/pry/commands/edit.rb +195 -0
  33. data/lib/pry/commands/edit/exception_patcher.rb +25 -0
  34. data/lib/pry/commands/edit/file_and_line_locator.rb +36 -0
  35. data/lib/pry/commands/exit.rb +42 -0
  36. data/lib/pry/commands/exit_all.rb +29 -0
  37. data/lib/pry/commands/exit_program.rb +23 -0
  38. data/lib/pry/commands/find_method.rb +193 -0
  39. data/lib/pry/commands/fix_indent.rb +19 -0
  40. data/lib/pry/commands/gem_cd.rb +26 -0
  41. data/lib/pry/commands/gem_install.rb +32 -0
  42. data/lib/pry/commands/gem_list.rb +33 -0
  43. data/lib/pry/commands/gem_open.rb +29 -0
  44. data/lib/pry/commands/gist.rb +101 -0
  45. data/lib/pry/commands/help.rb +164 -0
  46. data/lib/pry/commands/hist.rb +180 -0
  47. data/lib/pry/commands/import_set.rb +22 -0
  48. data/lib/pry/commands/install_command.rb +53 -0
  49. data/lib/pry/commands/jump_to.rb +29 -0
  50. data/lib/pry/commands/list_inspectors.rb +35 -0
  51. data/lib/pry/commands/list_prompts.rb +35 -0
  52. data/lib/pry/commands/ls.rb +114 -0
  53. data/lib/pry/commands/ls/constants.rb +47 -0
  54. data/lib/pry/commands/ls/formatter.rb +49 -0
  55. data/lib/pry/commands/ls/globals.rb +48 -0
  56. data/lib/pry/commands/ls/grep.rb +21 -0
  57. data/lib/pry/commands/ls/instance_vars.rb +39 -0
  58. data/lib/pry/commands/ls/interrogatable.rb +18 -0
  59. data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
  60. data/lib/pry/commands/ls/local_names.rb +35 -0
  61. data/lib/pry/commands/ls/local_vars.rb +39 -0
  62. data/lib/pry/commands/ls/ls_entity.rb +70 -0
  63. data/lib/pry/commands/ls/methods.rb +57 -0
  64. data/lib/pry/commands/ls/methods_helper.rb +46 -0
  65. data/lib/pry/commands/ls/self_methods.rb +32 -0
  66. data/lib/pry/commands/nesting.rb +25 -0
  67. data/lib/pry/commands/play.rb +103 -0
  68. data/lib/pry/commands/pry_backtrace.rb +25 -0
  69. data/lib/pry/commands/pry_version.rb +17 -0
  70. data/lib/pry/commands/raise_up.rb +32 -0
  71. data/lib/pry/commands/reload_code.rb +62 -0
  72. data/lib/pry/commands/reset.rb +18 -0
  73. data/lib/pry/commands/ri.rb +60 -0
  74. data/lib/pry/commands/save_file.rb +61 -0
  75. data/lib/pry/commands/shell_command.rb +48 -0
  76. data/lib/pry/commands/shell_mode.rb +25 -0
  77. data/lib/pry/commands/show_doc.rb +83 -0
  78. data/lib/pry/commands/show_info.rb +195 -0
  79. data/lib/pry/commands/show_input.rb +17 -0
  80. data/lib/pry/commands/show_source.rb +50 -0
  81. data/lib/pry/commands/simple_prompt.rb +22 -0
  82. data/lib/pry/commands/stat.rb +40 -0
  83. data/lib/pry/commands/switch_to.rb +23 -0
  84. data/lib/pry/commands/toggle_color.rb +24 -0
  85. data/lib/pry/commands/watch_expression.rb +105 -0
  86. data/lib/pry/commands/watch_expression/expression.rb +38 -0
  87. data/lib/pry/commands/whereami.rb +190 -0
  88. data/lib/pry/commands/wtf.rb +57 -0
  89. data/lib/pry/config.rb +24 -0
  90. data/lib/pry/config/behavior.rb +139 -0
  91. data/lib/pry/config/convenience.rb +26 -0
  92. data/lib/pry/config/default.rb +165 -0
  93. data/lib/pry/core_extensions.rb +131 -0
  94. data/lib/pry/editor.rb +133 -0
  95. data/lib/pry/exceptions.rb +77 -0
  96. data/lib/pry/helpers.rb +5 -0
  97. data/lib/pry/helpers/base_helpers.rb +113 -0
  98. data/lib/pry/helpers/command_helpers.rb +156 -0
  99. data/lib/pry/helpers/documentation_helpers.rb +75 -0
  100. data/lib/pry/helpers/options_helpers.rb +27 -0
  101. data/lib/pry/helpers/table.rb +109 -0
  102. data/lib/pry/helpers/text.rb +107 -0
  103. data/lib/pry/history.rb +125 -0
  104. data/lib/pry/history_array.rb +121 -0
  105. data/lib/pry/hooks.rb +230 -0
  106. data/lib/pry/indent.rb +406 -0
  107. data/lib/pry/input_completer.rb +242 -0
  108. data/lib/pry/input_lock.rb +132 -0
  109. data/lib/pry/inspector.rb +27 -0
  110. data/lib/pry/last_exception.rb +61 -0
  111. data/lib/pry/method.rb +546 -0
  112. data/lib/pry/method/disowned.rb +53 -0
  113. data/lib/pry/method/patcher.rb +125 -0
  114. data/lib/pry/method/weird_method_locator.rb +186 -0
  115. data/lib/pry/module_candidate.rb +136 -0
  116. data/lib/pry/object_path.rb +82 -0
  117. data/lib/pry/output.rb +50 -0
  118. data/lib/pry/pager.rb +234 -0
  119. data/lib/pry/plugins.rb +103 -0
  120. data/lib/pry/prompt.rb +26 -0
  121. data/lib/pry/pry_class.rb +375 -0
  122. data/lib/pry/pry_instance.rb +654 -0
  123. data/lib/pry/rbx_path.rb +22 -0
  124. data/lib/pry/repl.rb +202 -0
  125. data/lib/pry/repl_file_loader.rb +74 -0
  126. data/lib/pry/rubygem.rb +82 -0
  127. data/lib/pry/terminal.rb +79 -0
  128. data/lib/pry/test/helper.rb +170 -0
  129. data/lib/pry/version.rb +3 -0
  130. data/lib/pry/wrapped_module.rb +373 -0
  131. metadata +248 -0
data/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ License
2
+ -------
3
+
4
+ (The MIT License)
5
+
6
+ Copyright (c) 2013 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.
data/README.md ADDED
@@ -0,0 +1,406 @@
1
+ [![Build Status](https://img.shields.io/travis/pry/pry.svg)](https://travis-ci.org/pry/pry)
2
+ [![Code Climate](https://img.shields.io/codeclimate/github/pry/pry.svg)](https://codeclimate.com/github/pry/pry)
3
+ [![Inline docs](http://inch-pages.github.io/github/pry/pry.svg)](http://inch-pages.github.io/github/pry/pry)
4
+
5
+ <center>
6
+ ![The Pry Logo](https://dl.dropbox.com/u/26521875/pry%20stuff/logo/pry_logo_350.png)
7
+
8
+ © John Mair ([banisterfiend](https://twitter.com/banisterfiend)) 2013<br>
9
+
10
+ **Please** [DONATE](http://www.pledgie.com/campaigns/15899) to the Pry project - Pry was a **huge** amount of work and every donation received is encouraging and supports Pry's continued development!
11
+
12
+ **Sponsors**
13
+
14
+ [Tealeaf Academy](www.gotealeaf.com)<br/>
15
+ [Atomic Object](http://www.atomicobject.com/)<br/>
16
+ [Hashrocket](http://hashrocket.com/)<br/>
17
+ [Intridea](http://intridea.com/)<br/>
18
+ [Gaslight](http://gaslight.co/home)<br/>
19
+
20
+ **Other Resources**
21
+
22
+ [Skip to the website (recommended)](http://pry.github.com) <br />
23
+ [Skip to the wiki](https://github.com/pry/pry/wiki)
24
+ </center>
25
+
26
+ Pry is a powerful alternative to the standard IRB shell for Ruby. It is
27
+ written from scratch to provide a number of advanced features,
28
+ including:
29
+
30
+ * Source code browsing (including core C source with the pry-doc gem)
31
+ * Documentation browsing
32
+ * Live help system
33
+ * Open methods in editors (`edit Class#method`)
34
+ * Syntax highlighting
35
+ * Command shell integration (start editors, run git, and rake from within Pry)
36
+ * Gist integration
37
+ * Navigation around state (`cd`, `ls` and friends)
38
+ * Runtime invocation (use Pry as a developer console or debugger)
39
+ * Exotic object support (BasicObject instances, IClasses, ...)
40
+ * A Powerful and flexible command system
41
+ * Ability to view and replay history
42
+ * Many convenience commands inspired by IPython, Smalltalk and other advanced REPLs
43
+ * A wide-range number of [plugins](https://github.com/pry/pry/wiki/Available-plugins) that provide remote sessions, full debugging functionality, and more.
44
+
45
+ Pry also aims to be more than an IRB replacement; it is an
46
+ attempt to bring REPL driven programming to the Ruby language. It is
47
+ currently not as powerful as tools like [SLIME](http://en.wikipedia.org/wiki/SLIME) for lisp, but that is the
48
+ general direction Pry is heading.
49
+
50
+ Pry is also fairly flexible and allows significant user
51
+ [customization](https://github.com/pry/pry/wiki/Customization-and-configuration)
52
+ is trivial to set it to read from any object that has a `readline` method and write to any object that has a
53
+ `puts` method - many other aspects of Pry are also configurable making
54
+ it a good choice for implementing custom shells.
55
+
56
+ Pry comes with an executable so it can be invoked at the command line.
57
+ Just enter `pry` to start. A `.pryrc` file in the user's home directory will
58
+ be loaded if it exists. Type `pry --help` at the command line for more
59
+ information.
60
+
61
+ Try `gem install pry-doc` for additional documentation on Ruby Core
62
+ methods. The additional docs are accessed through the `show-doc` and
63
+ `show-method` commands.
64
+
65
+ * Install the [gem](https://rubygems.org/gems/pry): `gem install pry`
66
+ * Browse the comprehensive [documentation at the official Pry wiki](https://github.com/pry/pry/wiki)
67
+ * Read the [YARD API documentation](http://rdoc.info/github/pry/pry/master/file/README.markdown)
68
+ * See the [source code](http://github.com/pry/pry)
69
+
70
+ ### Commands
71
+
72
+ Nearly every piece of functionality in a Pry session is implemented as
73
+ a command. Commands are not methods and must start at the beginning of a line, with no
74
+ whitespace in between. Commands support a flexible syntax and allow
75
+ 'options' in the same way as shell commands, for example the following
76
+ Pry command will show a list of all private instance methods (in
77
+ scope) that begin with 'pa'
78
+
79
+ pry(YARD::Parser::SourceParser):5> ls -Mp --grep ^pa
80
+ YARD::Parser::SourceParser#methods: parse parser_class parser_type parser_type= parser_type_for_filename
81
+
82
+ ### Navigating around state
83
+
84
+ Pry allows us to pop in and out of different scopes (objects) using
85
+ the `cd` command. This enables us to explore the run-time view of a
86
+ program or library. To view which variables and methods are available
87
+ within a particular scope we use the versatile [ls command.](https://gist.github.com/c0fc686ef923c8b87715)
88
+
89
+ Here we will begin Pry at top-level, then Pry on a class and then on
90
+ an instance variable inside that class:
91
+
92
+ pry(main)> class Hello
93
+ pry(main)* @x = 20
94
+ pry(main)* end
95
+ => 20
96
+ pry(main)> cd Hello
97
+ pry(Hello):1> ls -i
98
+ instance variables: @x
99
+ pry(Hello):1> cd @x
100
+ pry(20):2> self + 10
101
+ => 30
102
+ pry(20):2> cd ..
103
+ pry(Hello):1> cd ..
104
+ pry(main)> cd ..
105
+
106
+ The number after the `:` in the pry prompt indicates the nesting
107
+ level. To display more information about nesting, use the `nesting`
108
+ command. E.g
109
+
110
+ pry("friend"):3> nesting
111
+ Nesting status:
112
+ 0. main (Pry top level)
113
+ 1. Hello
114
+ 2. 100
115
+ 3. "friend"
116
+ => nil
117
+
118
+ We can then jump back to any of the previous nesting levels by using
119
+ the `jump-to` command:
120
+
121
+ pry("friend"):3> jump-to 1
122
+ => 100
123
+ pry(Hello):1>
124
+
125
+ ### Runtime invocation
126
+
127
+ Pry can be invoked in the middle of a running program. It opens a Pry
128
+ session at the point it's called and makes all program state at that
129
+ point available. It can be invoked on any object using the
130
+ `my_object.pry` syntax or on the current binding (or any binding)
131
+ using `binding.pry`. The Pry session will then begin within the scope
132
+ of the object (or binding). When the session ends the program continues with any
133
+ modifications you made to it.
134
+
135
+ This functionality can be used for such things as: debugging,
136
+ implementing developer consoles and applying hot patches.
137
+
138
+ code:
139
+
140
+ # test.rb
141
+ require 'pry'
142
+
143
+ class A
144
+ def hello() puts "hello world!" end
145
+ end
146
+
147
+ a = A.new
148
+
149
+ # start a REPL session
150
+ binding.pry
151
+
152
+ # program resumes here (after pry session)
153
+ puts "program resumes here."
154
+
155
+ Pry session:
156
+
157
+ pry(main)> a.hello
158
+ hello world!
159
+ => nil
160
+ pry(main)> def a.goodbye
161
+ pry(main)* puts "goodbye cruel world!"
162
+ pry(main)* end
163
+ => nil
164
+ pry(main)> a.goodbye
165
+ goodbye cruel world!
166
+ => nil
167
+ pry(main)> exit
168
+
169
+ program resumes here.
170
+
171
+ ### Command Shell Integration
172
+
173
+ A line of input that begins with a '.' will be forwarded to the
174
+ command shell. This enables us to navigate the file system, spawn
175
+ editors, and run git and rake directly from within Pry.
176
+
177
+ Further, we can use the `shell-mode` command to incorporate the
178
+ present working directory into the Pry prompt and bring in (limited at this stage, sorry) file name completion.
179
+ We can also interpolate Ruby code directly into the shell by
180
+ using the normal `#{}` string interpolation syntax.
181
+
182
+ In the code below we're going to switch to `shell-mode` and edit the
183
+ `.pryrc` file in the home directory. We'll then cat its contents and
184
+ reload the file.
185
+
186
+ pry(main)> shell-mode
187
+ pry main:/home/john/ruby/projects/pry $ .cd ~
188
+ pry main:/home/john $ .emacsclient .pryrc
189
+ pry main:/home/john $ .cat .pryrc
190
+ def hello_world
191
+ puts "hello world!"
192
+ end
193
+ pry main:/home/john $ load ".pryrc"
194
+ => true
195
+ pry main:/home/john $ hello_world
196
+ hello world!
197
+
198
+ We can also interpolate Ruby code into the shell. In the
199
+ example below we use the shell command `cat` on a random file from the
200
+ current directory and count the number of lines in that file with
201
+ `wc`:
202
+
203
+ pry main:/home/john $ .cat #{Dir['*.*'].sample} | wc -l
204
+ 44
205
+
206
+ ### Code Browsing
207
+
208
+ You can browse method source code with the `show-method` command. Nearly all Ruby methods (and some C methods, with the pry-doc
209
+ gem) can have their source viewed. Code that is longer than a page is
210
+ sent through a pager (such as less), and all code is properly syntax
211
+ highlighted (even C code).
212
+
213
+ The `show-method` command accepts two syntaxes, the typical ri
214
+ `Class#method` syntax and also simply the name of a method that's in
215
+ scope. You can optionally pass the `-l` option to show-method to
216
+ include line numbers in the output.
217
+
218
+ In the following example we will enter the `Pry` class, list the
219
+ instance methods beginning with 're' and display the source code for the `rep` method:
220
+
221
+ pry(main)> cd Pry
222
+ pry(Pry):1> ls -M --grep re
223
+ Pry#methods: re readline refresh rep repl repl_epilogue repl_prologue retrieve_line
224
+ pry(Pry):1> show-method rep -l
225
+
226
+ From: /home/john/ruby/projects/pry/lib/pry/pry_instance.rb @ line 143:
227
+ Number of lines: 6
228
+
229
+ 143: def rep(target=TOPLEVEL_BINDING)
230
+ 144: target = Pry.binding_for(target)
231
+ 145: result = re(target)
232
+ 146:
233
+ 147: show_result(result) if should_print?
234
+ 148: end
235
+
236
+ Note that we can also view C methods (from Ruby Core) using the
237
+ `pry-doc` plugin; we also show off the alternate syntax for
238
+ `show-method`:
239
+
240
+ pry(main)> show-method Array#select
241
+
242
+ From: array.c in Ruby Core (C Method):
243
+ Number of lines: 15
244
+
245
+ static VALUE
246
+ rb_ary_select(VALUE ary)
247
+ {
248
+ VALUE result;
249
+ long i;
250
+
251
+ RETURN_ENUMERATOR(ary, 0, 0);
252
+ result = rb_ary_new2(RARRAY_LEN(ary));
253
+ for (i = 0; i < RARRAY_LEN(ary); i++) {
254
+ if (RTEST(rb_yield(RARRAY_PTR(ary)[i]))) {
255
+ rb_ary_push(result, rb_ary_elt(ary, i));
256
+ }
257
+ }
258
+ return result;
259
+ }
260
+
261
+ ### Documentation Browsing
262
+
263
+ One use-case for Pry is to explore a program at run-time by `cd`-ing
264
+ in and out of objects and viewing and invoking methods. In the course
265
+ of exploring it may be useful to read the documentation for a
266
+ specific method that you come across. Like `show-method` the `show-doc` command supports
267
+ two syntaxes - the normal `ri` syntax as well as accepting the name of
268
+ any method that is currently in scope.
269
+
270
+ The Pry documentation system does not rely on pre-generated `rdoc` or
271
+ `ri`, instead it grabs the comments directly above the method on
272
+ demand. This results in speedier documentation retrieval and allows
273
+ the Pry system to retrieve documentation for methods that would not be
274
+ picked up by `rdoc`. Pry also has a basic understanding of both the
275
+ rdoc and yard formats and will attempt to syntax highlight the
276
+ documentation appropriately.
277
+
278
+ Nonetheless, the `ri` functionality is very good and
279
+ has an advantage over Pry's system in that it allows documentation
280
+ lookup for classes as well as methods. Pry therefore has good
281
+ integration with `ri` through the `ri` command. The syntax
282
+ for the command is exactly as it would be in command-line -
283
+ so it is not necessary to quote strings.
284
+
285
+ In our example we will enter the `Gem` class and view the
286
+ documentation for the `try_activate` method:
287
+
288
+ pry(main)> cd Gem
289
+ pry(Gem):1> show-doc try_activate
290
+
291
+ From: /Users/john/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems.rb @ line 201:
292
+ Number of lines: 3
293
+
294
+ Try to activate a gem containing path. Returns true if
295
+ activation succeeded or wasn't needed because it was already
296
+ activated. Returns false if it can't find the path in a gem.
297
+ pry(Gem):1>
298
+
299
+ We can also use `ri` in the normal way:
300
+
301
+ pry(main) ri Array#each
302
+ ----------------------------------------------------------- Array#each
303
+ array.each {|item| block } -> array
304
+ ------------------------------------------------------------------------
305
+ Calls _block_ once for each element in _self_, passing that element
306
+ as a parameter.
307
+
308
+ a = [ "a", "b", "c" ]
309
+ a.each {|x| print x, " -- " }
310
+
311
+ produces:
312
+
313
+ a -- b -- c --
314
+
315
+ ### Gist integration
316
+
317
+ If the `gist` gem is installed then method source or documentation can be gisted to github with the
318
+ `gist` command. The `gist` command is capable of gisting [almost any REPL content](https://gist.github.com/cae143e4533416529726), including methods, documentation,
319
+ input expressions, command source, and so on. In the example below we will gist the C source
320
+ code for the `Symbol#to_proc` method to github:
321
+
322
+ pry(main)> gist -m Symbol#to_proc
323
+ Gist created at https://gist.github.com/5332c38afc46d902ce46 and added to clipboard.
324
+ pry(main)>
325
+
326
+ You can see the actual gist generated here: [https://gist.github.com/5332c38afc46d902ce46](https://gist.github.com/5332c38afc46d902ce46)
327
+
328
+ ### Edit methods
329
+
330
+ You can use `edit Class#method` or `edit my_method`
331
+ (if the method is in scope) to open a method for editing directly in
332
+ your favorite editor. Pry has knowledge of a few different editors and
333
+ will attempt to open the file at the line the method is defined.
334
+
335
+ You can set the editor to use by assigning to the `Pry.editor`
336
+ accessor. `Pry.editor` will default to `$EDITOR` or failing that will
337
+ use `nano` as the backup default. The file that is edited will be
338
+ automatically reloaded after exiting the editor - reloading can be
339
+ suppressed by passing the `--no-reload` option to `edit`
340
+
341
+ In the example below we will set our default editor to "emacsclient"
342
+ and open the `Pry#repl` method for editing:
343
+
344
+ pry(main)> Pry.editor = "emacsclient"
345
+ pry(main)> edit Pry#repl
346
+
347
+ ### Live Help System
348
+
349
+ Many other commands are available in Pry; to see the full list type
350
+ `help` at the prompt. A short description of each command is provided
351
+ with basic instructions for use; some commands have a more extensive
352
+ help that can be accessed via typing `command_name --help`. A command
353
+ will typically say in its description if the `--help` option is
354
+ avaiable.
355
+
356
+ ### Use Pry as your Rails Console
357
+
358
+ The recommended way to use Pry as your Rails console is to add
359
+ [the `pry-rails` gem](https://github.com/rweng/pry-rails) to
360
+ your Gemfile. This replaces the default console with Pry, in
361
+ addition to loading the Rails console helpers and adding some
362
+ useful Rails-specific commands.
363
+
364
+ If you don't want to change your Gemfile, you can still run a Pry
365
+ console in your app's environment using Pry's `-r` flag:
366
+
367
+ pry -r ./config/environment
368
+
369
+ Also check out the [wiki](https://github.com/pry/pry/wiki/Setting-up-Rails-or-Heroku-to-use-Pry)
370
+ for more information about integrating Pry with Rails.
371
+
372
+ ### Limitations:
373
+
374
+ * Tab completion is currently a bit broken/limited this will have a
375
+ major overhaul in a future version.
376
+
377
+ ### Syntax Highlighting
378
+
379
+ Syntax highlighting is on by default in Pry. If you want to change
380
+ the colors, check out the [pry-theme](https://github.com/kyrylo/pry-theme)
381
+ gem.
382
+
383
+ You can toggle the syntax highlighting on and off in a session by
384
+ using the `toggle-color` command. Alternatively, you can turn it off
385
+ permanently by putting the line `Pry.color = false` in your `~/.pryrc`
386
+ file.
387
+
388
+ ### Future Directions
389
+
390
+ Many new features are planned such as:
391
+
392
+ * Increase modularity (rely more on plugin system)
393
+ * Much improved documentation system, better support for YARD
394
+ * Better support for code and method reloading and saving code
395
+ * Extended and more sophisticated command system, allowing piping
396
+ between commands and running commands in background
397
+
398
+ ### Contact
399
+
400
+ Problems or questions? file an issue at [github](https://github.com/pry/pry/issues)
401
+
402
+ ### Contributors
403
+
404
+ Pry is primarily the work of [John Mair (banisterfiend)](http://github.com/banister), for full list
405
+ of contributors see the
406
+ [CONTRIBUTORS](https://github.com/pry/pry/blob/master/CONTRIBUTORS) file.
data/bin/pry ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # (C) John Mair (banisterfiend)
4
+ # MIT license
5
+
6
+ $0 = 'pry'
7
+
8
+ begin
9
+ require 'pry'
10
+ rescue LoadError
11
+ require 'rubygems'
12
+ require 'pry'
13
+ end
14
+
15
+ # Process command line options and run Pry
16
+ Pry::CLI.parse_options
data/lib/pry.rb ADDED
@@ -0,0 +1,161 @@
1
+ # (C) John Mair (banisterfiend) 2013
2
+ # MIT License
3
+ #
4
+ require 'pp'
5
+
6
+ require 'pry/input_lock'
7
+ require 'pry/exceptions'
8
+ require 'pry/helpers/base_helpers'
9
+ require 'pry/hooks'
10
+ require 'forwardable'
11
+
12
+ class Pry
13
+ # The default hooks - display messages when beginning and ending Pry sessions.
14
+ DEFAULT_HOOKS = Pry::Hooks.new.add_hook(:before_session, :default) do |out, target, _pry_|
15
+ next if _pry_.quiet?
16
+ _pry_.run_command("whereami --quiet")
17
+ end
18
+
19
+ # The default print
20
+ DEFAULT_PRINT = proc do |output, value, _pry_|
21
+ _pry_.pager.open do |pager|
22
+ pager.print _pry_.config.output_prefix
23
+ Pry::ColorPrinter.pp(value, pager, Pry::Terminal.width! - 1)
24
+ end
25
+ end
26
+
27
+ # may be convenient when working with enormous objects and
28
+ # pretty_print is too slow
29
+ SIMPLE_PRINT = proc do |output, value|
30
+ begin
31
+ output.puts value.inspect
32
+ rescue RescuableException
33
+ output.puts "unknown"
34
+ end
35
+ end
36
+
37
+ # useful when playing with truly enormous objects
38
+ CLIPPED_PRINT = proc do |output, value|
39
+ output.puts Pry.view_clip(value, id: true)
40
+ end
41
+
42
+ # Will only show the first line of the backtrace
43
+ DEFAULT_EXCEPTION_HANDLER = proc do |output, exception, _|
44
+ if UserError === exception && SyntaxError === exception
45
+ output.puts "SyntaxError: #{exception.message.sub(/.*syntax error, */m, '')}"
46
+ else
47
+ output.puts "#{exception.class}: #{exception.message}"
48
+ output.puts "from #{exception.backtrace.first}"
49
+ end
50
+ end
51
+
52
+ DEFAULT_PROMPT_NAME = 'pry'
53
+
54
+ # The default prompt; includes the target and nesting level
55
+ DEFAULT_PROMPT = [
56
+ proc { |target_self, nest_level, pry|
57
+ "[#{pry.input_array.size}] #{pry.config.prompt_name}(#{Pry.view_clip(target_self)})#{":#{nest_level}" unless nest_level.zero?}> "
58
+ },
59
+
60
+ proc { |target_self, nest_level, pry|
61
+ "[#{pry.input_array.size}] #{pry.config.prompt_name}(#{Pry.view_clip(target_self)})#{":#{nest_level}" unless nest_level.zero?}* "
62
+ }
63
+ ]
64
+
65
+ DEFAULT_PROMPT_SAFE_OBJECTS = [String, Numeric, Symbol, nil, true, false]
66
+
67
+ # A simple prompt - doesn't display target or nesting level
68
+ SIMPLE_PROMPT = [proc { ">> " }, proc { " | " }]
69
+
70
+ NO_PROMPT = [proc { '' }, proc { '' }]
71
+
72
+ SHELL_PROMPT = [
73
+ proc { |target_self, _, _pry_| "#{_pry_.config.prompt_name} #{Pry.view_clip(target_self)}:#{Dir.pwd} $ " },
74
+ proc { |target_self, _, _pry_| "#{_pry_.config.prompt_name} #{Pry.view_clip(target_self)}:#{Dir.pwd} * " }
75
+ ]
76
+
77
+ # A prompt that includes the full object path as well as
78
+ # input/output (_in_ and _out_) information. Good for navigation.
79
+ NAV_PROMPT = [
80
+ proc do |_, _, _pry_|
81
+ tree = _pry_.binding_stack.map { |b| Pry.view_clip(b.eval("self")) }.join " / "
82
+ "[#{_pry_.input_array.count}] (#{_pry_.config.prompt_name}) #{tree}: #{_pry_.binding_stack.size - 1}> "
83
+ end,
84
+ proc do |_, _, _pry_|
85
+ tree = _pry_.binding_stack.map { |b| Pry.view_clip(b.eval("self")) }.join " / "
86
+ "[#{_pry_.input_array.count}] (#{ _pry_.config.prompt_name}) #{tree}: #{_pry_.binding_stack.size - 1}* "
87
+ end,
88
+ ]
89
+
90
+ # Deal with the ^D key being pressed. Different behaviour in different cases:
91
+ # 1. In an expression behave like `!` command.
92
+ # 2. At top-level session behave like `exit` command.
93
+ # 3. In a nested session behave like `cd ..`.
94
+ DEFAULT_CONTROL_D_HANDLER = proc do |eval_string, _pry_|
95
+ if !eval_string.empty?
96
+ eval_string.replace('') # Clear input buffer.
97
+ elsif _pry_.binding_stack.one?
98
+ _pry_.binding_stack.clear
99
+ throw(:breakout)
100
+ else
101
+ # Otherwise, saves current binding stack as old stack and pops last
102
+ # binding out of binding stack (the old stack still has that binding).
103
+ _pry_.command_state["cd"] ||= Pry::Config.from_hash({}) # FIXME
104
+ _pry_.command_state['cd'].old_stack = _pry_.binding_stack.dup
105
+ _pry_.binding_stack.pop
106
+ end
107
+ end
108
+
109
+ DEFAULT_SYSTEM = proc do |output, cmd, _|
110
+ if !system(cmd)
111
+ output.puts "Error: there was a problem executing system command: #{cmd}"
112
+ end
113
+ end
114
+
115
+ # Store the current working directory. This allows show-source etc. to work if
116
+ # your process has changed directory since boot. [Issue #675]
117
+ INITIAL_PWD = Dir.pwd
118
+
119
+ # This is to keep from breaking under Rails 3.2 for people who are doing that
120
+ # IRB = Pry thing.
121
+ module ExtendCommandBundle; end
122
+ end
123
+
124
+ require 'method_source'
125
+ require 'shellwords'
126
+ require 'stringio'
127
+ require 'coderay'
128
+ require 'slop'
129
+ require 'rbconfig'
130
+ require 'tempfile'
131
+ require 'pathname'
132
+
133
+ require 'pry/version'
134
+ require 'pry/repl'
135
+ require 'pry/rbx_path'
136
+ require 'pry/code'
137
+ require 'pry/history_array'
138
+ require 'pry/helpers'
139
+ require 'pry/code_object'
140
+ require 'pry/method'
141
+ require 'pry/wrapped_module'
142
+ require 'pry/history'
143
+ require 'pry/command'
144
+ require 'pry/command_set'
145
+ require 'pry/commands'
146
+ require 'pry/plugins'
147
+ require 'pry/core_extensions'
148
+ require 'pry/pry_class'
149
+ require 'pry/pry_instance'
150
+ require 'pry/cli'
151
+ require 'pry/color_printer'
152
+ require 'pry/pager'
153
+ require 'pry/terminal'
154
+ require 'pry/editor'
155
+ require 'pry/rubygem'
156
+ require "pry/indent"
157
+ require "pry/last_exception"
158
+ require "pry/prompt"
159
+ require "pry/inspector"
160
+ require 'pry/object_path'
161
+ require 'pry/output'