pry 0.10.pre.1-java → 0.10.0.pre2-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +702 -0
  3. data/LICENSE +2 -2
  4. data/{README.markdown → README.md} +41 -35
  5. data/lib/pry.rb +82 -139
  6. data/lib/pry/cli.rb +77 -30
  7. data/lib/pry/code.rb +126 -182
  8. data/lib/pry/code/code_file.rb +103 -0
  9. data/lib/pry/code/code_range.rb +71 -0
  10. data/lib/pry/code/loc.rb +92 -0
  11. data/lib/pry/code_object.rb +172 -0
  12. data/lib/pry/color_printer.rb +55 -0
  13. data/lib/pry/command.rb +184 -28
  14. data/lib/pry/command_set.rb +113 -59
  15. data/lib/pry/commands.rb +4 -27
  16. data/lib/pry/commands/amend_line.rb +99 -0
  17. data/lib/pry/commands/bang.rb +20 -0
  18. data/lib/pry/commands/bang_pry.rb +17 -0
  19. data/lib/pry/commands/cat.rb +62 -0
  20. data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
  21. data/lib/pry/commands/cat/exception_formatter.rb +77 -0
  22. data/lib/pry/commands/cat/file_formatter.rb +67 -0
  23. data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
  24. data/lib/pry/commands/cd.rb +41 -0
  25. data/lib/pry/commands/change_inspector.rb +27 -0
  26. data/lib/pry/commands/change_prompt.rb +26 -0
  27. data/lib/pry/commands/code_collector.rb +165 -0
  28. data/lib/pry/commands/disable_pry.rb +27 -0
  29. data/lib/pry/commands/disabled_commands.rb +2 -0
  30. data/lib/pry/commands/easter_eggs.rb +112 -0
  31. data/lib/pry/commands/edit.rb +195 -0
  32. data/lib/pry/commands/edit/exception_patcher.rb +25 -0
  33. data/lib/pry/commands/edit/file_and_line_locator.rb +36 -0
  34. data/lib/pry/commands/exit.rb +42 -0
  35. data/lib/pry/commands/exit_all.rb +29 -0
  36. data/lib/pry/commands/exit_program.rb +23 -0
  37. data/lib/pry/commands/find_method.rb +193 -0
  38. data/lib/pry/commands/fix_indent.rb +19 -0
  39. data/lib/pry/commands/gem_cd.rb +26 -0
  40. data/lib/pry/commands/gem_install.rb +32 -0
  41. data/lib/pry/commands/gem_list.rb +33 -0
  42. data/lib/pry/commands/gem_open.rb +29 -0
  43. data/lib/pry/commands/gist.rb +101 -0
  44. data/lib/pry/commands/help.rb +164 -0
  45. data/lib/pry/commands/hist.rb +180 -0
  46. data/lib/pry/commands/import_set.rb +22 -0
  47. data/lib/pry/commands/install_command.rb +53 -0
  48. data/lib/pry/commands/jump_to.rb +29 -0
  49. data/lib/pry/commands/list_inspectors.rb +35 -0
  50. data/lib/pry/commands/list_prompts.rb +35 -0
  51. data/lib/pry/commands/ls.rb +114 -0
  52. data/lib/pry/commands/ls/constants.rb +47 -0
  53. data/lib/pry/commands/ls/formatter.rb +49 -0
  54. data/lib/pry/commands/ls/globals.rb +48 -0
  55. data/lib/pry/commands/ls/grep.rb +21 -0
  56. data/lib/pry/commands/ls/instance_vars.rb +39 -0
  57. data/lib/pry/commands/ls/interrogatable.rb +18 -0
  58. data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
  59. data/lib/pry/commands/ls/local_names.rb +35 -0
  60. data/lib/pry/commands/ls/local_vars.rb +39 -0
  61. data/lib/pry/commands/ls/ls_entity.rb +70 -0
  62. data/lib/pry/commands/ls/methods.rb +57 -0
  63. data/lib/pry/commands/ls/methods_helper.rb +46 -0
  64. data/lib/pry/commands/ls/self_methods.rb +32 -0
  65. data/lib/pry/commands/nesting.rb +25 -0
  66. data/lib/pry/commands/play.rb +103 -0
  67. data/lib/pry/commands/pry_backtrace.rb +25 -0
  68. data/lib/pry/commands/pry_version.rb +17 -0
  69. data/lib/pry/commands/raise_up.rb +32 -0
  70. data/lib/pry/commands/reload_code.rb +62 -0
  71. data/lib/pry/commands/reset.rb +18 -0
  72. data/lib/pry/commands/ri.rb +60 -0
  73. data/lib/pry/commands/save_file.rb +61 -0
  74. data/lib/pry/commands/shell_command.rb +48 -0
  75. data/lib/pry/commands/shell_mode.rb +25 -0
  76. data/lib/pry/commands/show_doc.rb +83 -0
  77. data/lib/pry/commands/show_info.rb +195 -0
  78. data/lib/pry/commands/show_input.rb +17 -0
  79. data/lib/pry/commands/show_source.rb +50 -0
  80. data/lib/pry/commands/simple_prompt.rb +22 -0
  81. data/lib/pry/commands/stat.rb +40 -0
  82. data/lib/pry/commands/switch_to.rb +23 -0
  83. data/lib/pry/commands/toggle_color.rb +24 -0
  84. data/lib/pry/commands/watch_expression.rb +105 -0
  85. data/lib/pry/commands/watch_expression/expression.rb +38 -0
  86. data/lib/pry/commands/whereami.rb +190 -0
  87. data/lib/pry/commands/wtf.rb +57 -0
  88. data/lib/pry/config.rb +20 -229
  89. data/lib/pry/config/behavior.rb +139 -0
  90. data/lib/pry/config/convenience.rb +26 -0
  91. data/lib/pry/config/default.rb +165 -0
  92. data/lib/pry/core_extensions.rb +59 -38
  93. data/lib/pry/editor.rb +133 -0
  94. data/lib/pry/exceptions.rb +77 -0
  95. data/lib/pry/helpers.rb +1 -0
  96. data/lib/pry/helpers/base_helpers.rb +40 -154
  97. data/lib/pry/helpers/command_helpers.rb +19 -130
  98. data/lib/pry/helpers/documentation_helpers.rb +21 -11
  99. data/lib/pry/helpers/table.rb +109 -0
  100. data/lib/pry/helpers/text.rb +8 -9
  101. data/lib/pry/history.rb +61 -45
  102. data/lib/pry/history_array.rb +11 -1
  103. data/lib/pry/hooks.rb +10 -32
  104. data/lib/pry/indent.rb +110 -38
  105. data/lib/pry/input_completer.rb +242 -0
  106. data/lib/pry/input_lock.rb +132 -0
  107. data/lib/pry/inspector.rb +27 -0
  108. data/lib/pry/last_exception.rb +61 -0
  109. data/lib/pry/method.rb +199 -200
  110. data/lib/pry/method/disowned.rb +53 -0
  111. data/lib/pry/method/patcher.rb +125 -0
  112. data/lib/pry/method/weird_method_locator.rb +186 -0
  113. data/lib/pry/module_candidate.rb +39 -33
  114. data/lib/pry/object_path.rb +82 -0
  115. data/lib/pry/output.rb +50 -0
  116. data/lib/pry/pager.rb +234 -0
  117. data/lib/pry/plugins.rb +4 -3
  118. data/lib/pry/prompt.rb +26 -0
  119. data/lib/pry/pry_class.rb +199 -227
  120. data/lib/pry/pry_instance.rb +344 -403
  121. data/lib/pry/rbx_path.rb +1 -1
  122. data/lib/pry/repl.rb +202 -0
  123. data/lib/pry/repl_file_loader.rb +20 -26
  124. data/lib/pry/rubygem.rb +82 -0
  125. data/lib/pry/terminal.rb +79 -0
  126. data/lib/pry/test/helper.rb +170 -0
  127. data/lib/pry/version.rb +1 -1
  128. data/lib/pry/wrapped_module.rb +133 -48
  129. metadata +132 -197
  130. data/.document +0 -2
  131. data/.gemtest +0 -0
  132. data/.gitignore +0 -16
  133. data/.travis.yml +0 -17
  134. data/.yardopts +0 -1
  135. data/CHANGELOG +0 -387
  136. data/CONTRIBUTORS +0 -36
  137. data/Gemfile +0 -2
  138. data/Rakefile +0 -137
  139. data/TODO +0 -117
  140. data/examples/example_basic.rb +0 -15
  141. data/examples/example_command_override.rb +0 -32
  142. data/examples/example_commands.rb +0 -36
  143. data/examples/example_hooks.rb +0 -9
  144. data/examples/example_image_edit.rb +0 -67
  145. data/examples/example_input.rb +0 -7
  146. data/examples/example_input2.rb +0 -29
  147. data/examples/example_output.rb +0 -11
  148. data/examples/example_print.rb +0 -6
  149. data/examples/example_prompt.rb +0 -9
  150. data/examples/helper.rb +0 -6
  151. data/lib/pry/completion.rb +0 -221
  152. data/lib/pry/custom_completions.rb +0 -6
  153. data/lib/pry/default_commands/cd.rb +0 -81
  154. data/lib/pry/default_commands/commands.rb +0 -62
  155. data/lib/pry/default_commands/context.rb +0 -98
  156. data/lib/pry/default_commands/easter_eggs.rb +0 -95
  157. data/lib/pry/default_commands/editing.rb +0 -420
  158. data/lib/pry/default_commands/find_method.rb +0 -169
  159. data/lib/pry/default_commands/gems.rb +0 -84
  160. data/lib/pry/default_commands/gist.rb +0 -187
  161. data/lib/pry/default_commands/help.rb +0 -127
  162. data/lib/pry/default_commands/hist.rb +0 -120
  163. data/lib/pry/default_commands/input_and_output.rb +0 -306
  164. data/lib/pry/default_commands/introspection.rb +0 -410
  165. data/lib/pry/default_commands/ls.rb +0 -272
  166. data/lib/pry/default_commands/misc.rb +0 -38
  167. data/lib/pry/default_commands/navigating_pry.rb +0 -110
  168. data/lib/pry/default_commands/whereami.rb +0 -92
  169. data/lib/pry/extended_commands/experimental.rb +0 -7
  170. data/lib/pry/rbx_method.rb +0 -13
  171. data/man/pry.1 +0 -195
  172. data/man/pry.1.html +0 -204
  173. data/man/pry.1.ronn +0 -141
  174. data/pry.gemspec +0 -46
  175. data/test/candidate_helper1.rb +0 -11
  176. data/test/candidate_helper2.rb +0 -8
  177. data/test/helper.rb +0 -223
  178. data/test/test_cli.rb +0 -78
  179. data/test/test_code.rb +0 -201
  180. data/test/test_command.rb +0 -712
  181. data/test/test_command_helpers.rb +0 -9
  182. data/test/test_command_integration.rb +0 -668
  183. data/test/test_command_set.rb +0 -610
  184. data/test/test_completion.rb +0 -62
  185. data/test/test_control_d_handler.rb +0 -45
  186. data/test/test_default_commands/example.erb +0 -5
  187. data/test/test_default_commands/test_cd.rb +0 -318
  188. data/test/test_default_commands/test_context.rb +0 -280
  189. data/test/test_default_commands/test_documentation.rb +0 -314
  190. data/test/test_default_commands/test_find_method.rb +0 -50
  191. data/test/test_default_commands/test_gems.rb +0 -18
  192. data/test/test_default_commands/test_help.rb +0 -57
  193. data/test/test_default_commands/test_input.rb +0 -428
  194. data/test/test_default_commands/test_introspection.rb +0 -511
  195. data/test/test_default_commands/test_ls.rb +0 -151
  196. data/test/test_default_commands/test_shell.rb +0 -343
  197. data/test/test_default_commands/test_show_source.rb +0 -432
  198. data/test/test_exception_whitelist.rb +0 -21
  199. data/test/test_history_array.rb +0 -65
  200. data/test/test_hooks.rb +0 -521
  201. data/test/test_indent.rb +0 -277
  202. data/test/test_input_stack.rb +0 -86
  203. data/test/test_method.rb +0 -401
  204. data/test/test_pry.rb +0 -463
  205. data/test/test_pry_defaults.rb +0 -419
  206. data/test/test_pry_history.rb +0 -84
  207. data/test/test_pry_output.rb +0 -41
  208. data/test/test_sticky_locals.rb +0 -155
  209. data/test/test_syntax_checking.rb +0 -65
  210. data/test/test_wrapped_module.rb +0 -174
  211. data/test/testrc +0 -2
  212. data/test/testrcbad +0 -2
  213. data/wiki/Customizing-pry.md +0 -397
  214. data/wiki/Home.md +0 -4
@@ -0,0 +1,39 @@
1
+ require 'pry/commands/ls/interrogatable'
2
+
3
+ class Pry
4
+ class Command::Ls < Pry::ClassCommand
5
+ class InstanceVars < Pry::Command::Ls::Formatter
6
+ include Pry::Command::Ls::Interrogatable
7
+
8
+ def initialize(interrogatee, no_user_opts, opts, _pry_)
9
+ super(_pry_)
10
+ @interrogatee = interrogatee
11
+ @no_user_opts = no_user_opts
12
+ @default_switch = opts[:ivars]
13
+ end
14
+
15
+ def correct_opts?
16
+ super || @no_user_opts
17
+ end
18
+
19
+ def output_self
20
+ ivars = if Object === @interrogatee
21
+ Pry::Method.safe_send(@interrogatee, :instance_variables)
22
+ else
23
+ [] #TODO: BasicObject support
24
+ end
25
+ kvars = Pry::Method.safe_send(interrogatee_mod, :class_variables)
26
+ ivars_out = output_section('instance variables', format(:instance_var, ivars))
27
+ kvars_out = output_section('class variables', format(:class_var, kvars))
28
+ ivars_out + kvars_out
29
+ end
30
+
31
+ private
32
+
33
+ def format(type, vars)
34
+ vars.sort_by { |var| var.to_s.downcase }.map { |var| color(type, var) }
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,18 @@
1
+ module Pry::Command::Ls::Interrogatable
2
+
3
+ private
4
+
5
+ def interrogating_a_module?
6
+ Module === @interrogatee
7
+ end
8
+
9
+ def interrogatee_mod
10
+ if interrogating_a_module?
11
+ @interrogatee
12
+ else
13
+ singleton = Pry::Method.singleton_class_of(@interrogatee)
14
+ singleton.ancestors.grep(::Class).reject { |c| c == singleton }.first
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,49 @@
1
+ module Pry::Command::Ls::JRubyHacks
2
+
3
+ private
4
+
5
+ # JRuby creates lots of aliases for methods imported from java in an attempt
6
+ # to make life easier for ruby programmers. (e.g. getFooBar becomes
7
+ # get_foo_bar and foo_bar, and maybe foo_bar? if it returns a Boolean). The
8
+ # full transformations are in the assignAliases method of:
9
+ # https://github.com/jruby/jruby/blob/master/src/org/jruby/javasupport/JavaClass.java
10
+ #
11
+ # This has the unfortunate side-effect of making the output of ls even more
12
+ # incredibly verbose than it normally would be for these objects; and so we
13
+ # filter out all but the nicest of these aliases here.
14
+ #
15
+ # TODO: This is a little bit vague, better heuristics could be used.
16
+ # JRuby also has a lot of scala-specific logic, which we don't copy.
17
+ def trim_jruby_aliases(methods)
18
+ grouped = methods.group_by do |m|
19
+ m.name.sub(/\A(is|get|set)(?=[A-Z_])/, '').gsub(/[_?=]/, '').downcase
20
+ end
21
+
22
+ grouped.map do |key, values|
23
+ values = values.sort_by do |m|
24
+ rubbishness(m.name)
25
+ end
26
+
27
+ found = []
28
+ values.select do |x|
29
+ (!found.any? { |y| x == y }) && found << x
30
+ end
31
+ end.flatten(1)
32
+ end
33
+
34
+ # When removing jruby aliases, we want to keep the alias that is
35
+ # "least rubbish" according to this metric.
36
+ def rubbishness(name)
37
+ name.each_char.map { |x|
38
+ case x
39
+ when /[A-Z]/
40
+ 1
41
+ when '?', '=', '!'
42
+ -2
43
+ else
44
+ 0
45
+ end
46
+ }.inject(&:+) + (name.size / 100.0)
47
+ end
48
+
49
+ end
@@ -0,0 +1,35 @@
1
+ class Pry
2
+ class Command::Ls < Pry::ClassCommand
3
+ class LocalNames < Pry::Command::Ls::Formatter
4
+
5
+ def initialize(no_user_opts, args, _pry_)
6
+ super(_pry_)
7
+ @no_user_opts = no_user_opts
8
+ @args = args
9
+ @sticky_locals = _pry_.sticky_locals
10
+ end
11
+
12
+ def correct_opts?
13
+ super || (@no_user_opts && @args.empty?)
14
+ end
15
+
16
+ def output_self
17
+ local_vars = grep.regexp[@target.eval('local_variables')]
18
+ output_section('locals', format(local_vars))
19
+ end
20
+
21
+ private
22
+
23
+ def format(locals)
24
+ locals.sort_by(&:downcase).map do |name|
25
+ if @sticky_locals.include?(name.to_sym)
26
+ color(:pry_var, name)
27
+ else
28
+ color(:local_var, name)
29
+ end
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,39 @@
1
+ class Pry
2
+ class Command::Ls < Pry::ClassCommand
3
+ class LocalVars < Pry::Command::Ls::Formatter
4
+
5
+ def initialize(opts, _pry_)
6
+ super(_pry_)
7
+ @default_switch = opts[:locals]
8
+ @sticky_locals = _pry_.sticky_locals
9
+ end
10
+
11
+ def output_self
12
+ name_value_pairs = @target.eval('local_variables').reject { |e|
13
+ @sticky_locals.keys.include?(e.to_sym)
14
+ }.map { |name|
15
+ [name, (@target.eval(name.to_s))]
16
+ }
17
+ format(name_value_pairs).join('')
18
+ end
19
+
20
+ private
21
+
22
+ def format(name_value_pairs)
23
+ name_value_pairs.sort_by { |name, value|
24
+ value.to_s.size
25
+ }.reverse.map { |name, value|
26
+ colorized_assignment_style(name, format_value(value))
27
+ }
28
+ end
29
+
30
+ def colorized_assignment_style(lhs, rhs, desired_width = 7)
31
+ colorized_lhs = color(:local_var, lhs)
32
+ color_escape_padding = colorized_lhs.size - lhs.size
33
+ pad = desired_width + color_escape_padding
34
+ "%-#{pad}s = %s" % [color(:local_var, colorized_lhs), rhs]
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,70 @@
1
+ require 'pry/commands/ls/grep'
2
+ require 'pry/commands/ls/formatter'
3
+ require 'pry/commands/ls/globals'
4
+ require 'pry/commands/ls/constants'
5
+ require 'pry/commands/ls/methods'
6
+ require 'pry/commands/ls/self_methods'
7
+ require 'pry/commands/ls/instance_vars'
8
+ require 'pry/commands/ls/local_names'
9
+ require 'pry/commands/ls/local_vars'
10
+
11
+ class Pry
12
+ class Command::Ls < Pry::ClassCommand
13
+
14
+ class LsEntity
15
+ attr_reader :_pry_
16
+
17
+ def initialize(opts)
18
+ @interrogatee = opts[:interrogatee]
19
+ @no_user_opts = opts[:no_user_opts]
20
+ @opts = opts[:opts]
21
+ @args = opts[:args]
22
+ @grep = Grep.new(Regexp.new(opts[:opts][:G] || '.'))
23
+ @_pry_ = opts.delete(:_pry_)
24
+ end
25
+
26
+ def entities_table
27
+ entities.map(&:write_out).reject { |o| !o }.join('')
28
+ end
29
+
30
+ private
31
+
32
+ def grep(entity)
33
+ entity.tap { |o| o.grep = @grep }
34
+ end
35
+
36
+ def globals
37
+ grep Globals.new(@opts, _pry_)
38
+ end
39
+
40
+ def constants
41
+ grep Constants.new(@interrogatee, @no_user_opts, @opts, _pry_)
42
+ end
43
+
44
+ def methods
45
+ grep(Methods.new(@interrogatee, @no_user_opts, @opts, _pry_))
46
+ end
47
+
48
+ def self_methods
49
+ grep SelfMethods.new(@interrogatee, @no_user_opts, @opts, _pry_)
50
+ end
51
+
52
+ def instance_vars
53
+ grep InstanceVars.new(@interrogatee, @no_user_opts, @opts, _pry_)
54
+ end
55
+
56
+ def local_names
57
+ grep LocalNames.new(@no_user_opts, @args, _pry_)
58
+ end
59
+
60
+ def local_vars
61
+ LocalVars.new(@opts, _pry_)
62
+ end
63
+
64
+ def entities
65
+ [globals, constants, methods, self_methods, instance_vars, local_names,
66
+ local_vars]
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,57 @@
1
+ require 'pry/commands/ls/methods_helper'
2
+ require 'pry/commands/ls/interrogatable'
3
+
4
+ class Pry
5
+ class Command::Ls < Pry::ClassCommand
6
+ class Methods < Pry::Command::Ls::Formatter
7
+
8
+ include Pry::Command::Ls::Interrogatable
9
+ include Pry::Command::Ls::MethodsHelper
10
+
11
+ def initialize(interrogatee, no_user_opts, opts, _pry_)
12
+ super(_pry_)
13
+ @interrogatee = interrogatee
14
+ @no_user_opts = no_user_opts
15
+ @default_switch = opts[:methods]
16
+ @instance_methods_switch = opts['instance-methods']
17
+ @ppp_switch = opts[:ppp]
18
+ @jruby_switch = opts['all-java']
19
+ @quiet_switch = opts[:quiet]
20
+ @verbose_switch = opts[:verbose]
21
+ end
22
+
23
+ def output_self
24
+ methods = all_methods.group_by(&:owner)
25
+ # Reverse the resolution order so that the most useful information
26
+ # appears right by the prompt.
27
+ resolution_order.take_while(&below_ceiling).reverse.map do |klass|
28
+ methods_here = (methods[klass] || []).select { |m| grep.regexp[m.name] }
29
+ heading = "#{ Pry::WrappedModule.new(klass).method_prefix }methods"
30
+ output_section(heading, format(methods_here))
31
+ end.join('')
32
+ end
33
+
34
+ private
35
+
36
+ def correct_opts?
37
+ super || @instance_methods_switch || @ppp_switch || @no_user_opts
38
+ end
39
+
40
+
41
+ # Get a lambda that can be used with `take_while` to prevent over-eager
42
+ # traversal of the Object's ancestry graph.
43
+ def below_ceiling
44
+ ceiling = if @quiet_switch
45
+ [Pry::Method.safe_send(interrogatee_mod, :ancestors)[1]] +
46
+ _pry_.config.ls.ceiling
47
+ elsif @verbose_switch
48
+ []
49
+ else
50
+ _pry_.config.ls.ceiling.dup
51
+ end
52
+ lambda { |klass| !ceiling.include?(klass) }
53
+ end
54
+
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,46 @@
1
+ require 'pry/commands/ls/jruby_hacks'
2
+
3
+ module Pry::Command::Ls::MethodsHelper
4
+
5
+ include Pry::Command::Ls::JRubyHacks
6
+
7
+ private
8
+
9
+ # Get all the methods that we'll want to output.
10
+ def all_methods(instance_methods = false)
11
+ methods = if instance_methods || @instance_methods_switch
12
+ Pry::Method.all_from_class(@interrogatee)
13
+ else
14
+ Pry::Method.all_from_obj(@interrogatee)
15
+ end
16
+
17
+ if Pry::Helpers::BaseHelpers.jruby? && !@jruby_switch
18
+ methods = trim_jruby_aliases(methods)
19
+ end
20
+
21
+ methods.select { |method| @ppp_switch || method.visibility == :public }
22
+ end
23
+
24
+ def resolution_order
25
+ if @instance_methods_switch
26
+ Pry::Method.instance_resolution_order(@interrogatee)
27
+ else
28
+ Pry::Method.resolution_order(@interrogatee)
29
+ end
30
+ end
31
+
32
+ def format(methods)
33
+ methods.sort_by(&:name).map do |method|
34
+ if method.name == 'method_missing'
35
+ color(:method_missing, 'method_missing')
36
+ elsif method.visibility == :private
37
+ color(:private_method, method.name)
38
+ elsif method.visibility == :protected
39
+ color(:protected_method, method.name)
40
+ else
41
+ color(:public_method, method.name)
42
+ end
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,32 @@
1
+ require 'pry/commands/ls/interrogatable'
2
+ require 'pry/commands/ls/methods_helper'
3
+
4
+ class Pry
5
+ class Command::Ls < Pry::ClassCommand
6
+ class SelfMethods < Pry::Command::Ls::Formatter
7
+ include Pry::Command::Ls::Interrogatable
8
+ include Pry::Command::Ls::MethodsHelper
9
+
10
+ def initialize(interrogatee, no_user_opts, opts, _pry_)
11
+ super(_pry_)
12
+ @interrogatee = interrogatee
13
+ @no_user_opts = no_user_opts
14
+ end
15
+
16
+ def output_self
17
+ methods = all_methods(true).select do |m|
18
+ m.owner == @interrogatee && grep.regexp[m.name]
19
+ end
20
+ heading = "#{ Pry::WrappedModule.new(@interrogatee).method_prefix }methods"
21
+ output_section(heading, format(methods))
22
+ end
23
+
24
+ private
25
+
26
+ def correct_opts?
27
+ @no_user_opts && interrogating_a_module?
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,25 @@
1
+ class Pry
2
+ class Command::Nesting < Pry::ClassCommand
3
+ match 'nesting'
4
+ group 'Navigating Pry'
5
+ description 'Show nesting information.'
6
+
7
+ banner <<-'BANNER'
8
+ Show nesting information.
9
+ BANNER
10
+
11
+ def process
12
+ output.puts 'Nesting status:'
13
+ output.puts '--'
14
+ _pry_.binding_stack.each_with_index do |obj, level|
15
+ if level == 0
16
+ output.puts "#{level}. #{Pry.view_clip(obj.eval('self'))} (Pry top level)"
17
+ else
18
+ output.puts "#{level}. #{Pry.view_clip(obj.eval('self'))}"
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ Pry::Commands.add_command(Pry::Command::Nesting)
25
+ end
@@ -0,0 +1,103 @@
1
+ class Pry
2
+ class Command::Play < Pry::ClassCommand
3
+ match 'play'
4
+ group 'Editing'
5
+ description 'Playback a string variable, method, line, or file as input.'
6
+
7
+ banner <<-'BANNER'
8
+ Usage: play [OPTIONS] [--help]
9
+
10
+ The play command enables you to replay code from files and methods as if they
11
+ were entered directly in the Pry REPL.
12
+
13
+ play --lines 149..153 # assumes current context
14
+ play -i 20 --lines 1..3 # assumes lines of the input expression at 20
15
+ play -o 4 # the output of of an expression at 4
16
+ play Pry#repl -l 1..-1 # play the contents of Pry#repl method
17
+ play -e 2 # play from specified line until end of valid expression
18
+ play hello.rb # play a file
19
+ play Rakefile -l 5 # play line 5 of a file
20
+ play -d hi # play documentation of hi method
21
+ play hi --open # play hi method and leave it open
22
+
23
+ https://github.com/pry/pry/wiki/User-Input#wiki-Play
24
+ BANNER
25
+
26
+ def options(opt)
27
+ CodeCollector.inject_options(opt)
28
+
29
+ opt.on :open, 'Plays the selected content except the last line. Useful' \
30
+ ' for replaying methods and leaving the method definition' \
31
+ ' "open". `amend-line` can then be used to' \
32
+ ' modify the method.'
33
+
34
+ opt.on :e, :expression=, 'Executes until end of valid expression', :as => Integer
35
+ opt.on :p, :print, 'Prints executed code'
36
+ end
37
+
38
+ def process
39
+ @cc = CodeCollector.new(args, opts, _pry_)
40
+
41
+ perform_play
42
+ show_input
43
+ end
44
+
45
+ def perform_play
46
+ eval_string << content_after_options
47
+ run "fix-indent"
48
+ end
49
+
50
+ def show_input
51
+ if opts.present?(:print) or !Pry::Code.complete_expression?(eval_string)
52
+ run "show-input"
53
+ end
54
+ end
55
+
56
+
57
+ def content_after_options
58
+ if opts.present?(:open)
59
+ restrict_to_lines(content, (0..-2))
60
+ elsif opts.present?(:expression)
61
+ content_at_expression
62
+ else
63
+ content
64
+ end
65
+ end
66
+
67
+ def content_at_expression
68
+ code_object.expression_at(opts[:expression])
69
+ end
70
+
71
+ def code_object
72
+ Pry::Code.new(content)
73
+ end
74
+
75
+ def should_use_default_file?
76
+ !args.first && !opts.present?(:in) && !opts.present?(:out)
77
+ end
78
+
79
+ def content
80
+ if should_use_default_file?
81
+ file_content
82
+ else
83
+ @cc.content
84
+ end
85
+ end
86
+
87
+ # The file to play from when no code object is specified.
88
+ # e.g `play --lines 4..10`
89
+ def default_file
90
+ target.eval("__FILE__") && File.expand_path(target.eval("__FILE__"))
91
+ end
92
+
93
+ def file_content
94
+ if default_file && File.exists?(default_file)
95
+ @cc.restrict_to_lines(File.read(default_file), @cc.line_range)
96
+ else
97
+ raise CommandError, "File does not exist! File was: #{default_file.inspect}"
98
+ end
99
+ end
100
+ end
101
+
102
+ Pry::Commands.add_command(Pry::Command::Play)
103
+ end