pry 0.10.2-i386-mswin32 → 1.0.0.pre1-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. data/.document +2 -0
  2. data/.gitignore +16 -0
  3. data/.travis.yml +21 -0
  4. data/.yardopts +3 -0
  5. data/CHANGELOG +503 -0
  6. data/CONTRIBUTORS +55 -0
  7. data/Gemfile +9 -0
  8. data/Guardfile +62 -0
  9. data/LICENSE +2 -2
  10. data/{README.md → README.markdown} +31 -37
  11. data/Rakefile +144 -0
  12. data/TODO +117 -0
  13. data/lib/pry.rb +146 -33
  14. data/lib/pry/cli.rb +13 -35
  15. data/lib/pry/code.rb +63 -24
  16. data/lib/pry/code/loc.rb +2 -2
  17. data/lib/pry/code_object.rb +21 -40
  18. data/lib/pry/command.rb +6 -9
  19. data/lib/pry/command_set.rb +37 -80
  20. data/lib/pry/commands.rb +1 -1
  21. data/lib/pry/commands/amend_line.rb +1 -1
  22. data/lib/pry/commands/bang.rb +1 -1
  23. data/lib/pry/commands/cat.rb +2 -11
  24. data/lib/pry/commands/cat/abstract_formatter.rb +1 -1
  25. data/lib/pry/commands/cat/exception_formatter.rb +7 -6
  26. data/lib/pry/commands/cat/file_formatter.rb +32 -15
  27. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  28. data/lib/pry/commands/cd.rb +3 -14
  29. data/lib/pry/commands/code_collector.rb +4 -4
  30. data/lib/pry/commands/easter_eggs.rb +3 -3
  31. data/lib/pry/commands/edit.rb +22 -10
  32. data/lib/pry/commands/edit/exception_patcher.rb +1 -1
  33. data/lib/pry/commands/edit/file_and_line_locator.rb +2 -0
  34. data/lib/pry/{method/patcher.rb → commands/edit/method_patcher.rb} +37 -40
  35. data/lib/pry/commands/find_method.rb +22 -16
  36. data/lib/pry/commands/gem_install.rb +2 -5
  37. data/lib/pry/commands/gem_open.rb +1 -1
  38. data/lib/pry/commands/gist.rb +11 -10
  39. data/lib/pry/commands/help.rb +14 -14
  40. data/lib/pry/commands/hist.rb +5 -24
  41. data/lib/pry/commands/ls.rb +287 -56
  42. data/lib/pry/commands/play.rb +10 -44
  43. data/lib/pry/commands/pry_backtrace.rb +2 -1
  44. data/lib/pry/commands/raise_up.rb +1 -1
  45. data/lib/pry/commands/reload_code.rb +15 -31
  46. data/lib/pry/commands/ri.rb +3 -7
  47. data/lib/pry/commands/shell_command.rb +12 -17
  48. data/lib/pry/commands/shell_mode.rb +2 -2
  49. data/lib/pry/commands/show_doc.rb +0 -5
  50. data/lib/pry/commands/show_info.rb +10 -11
  51. data/lib/pry/commands/show_source.rb +3 -15
  52. data/lib/pry/commands/simple_prompt.rb +1 -1
  53. data/lib/pry/commands/toggle_color.rb +4 -8
  54. data/lib/pry/commands/whereami.rb +10 -18
  55. data/lib/pry/completion.rb +293 -0
  56. data/lib/pry/config.rb +233 -20
  57. data/lib/pry/core_extensions.rb +19 -29
  58. data/lib/pry/custom_completions.rb +6 -0
  59. data/lib/pry/editor.rb +103 -109
  60. data/lib/pry/helpers/base_helpers.rb +109 -22
  61. data/lib/pry/helpers/command_helpers.rb +8 -10
  62. data/lib/pry/helpers/documentation_helpers.rb +2 -1
  63. data/lib/pry/helpers/text.rb +5 -4
  64. data/lib/pry/history.rb +10 -21
  65. data/lib/pry/history_array.rb +0 -5
  66. data/lib/pry/hooks.rb +29 -9
  67. data/lib/pry/indent.rb +10 -5
  68. data/lib/pry/method.rb +86 -81
  69. data/lib/pry/method/weird_method_locator.rb +2 -4
  70. data/lib/pry/module_candidate.rb +14 -5
  71. data/lib/pry/pager.rb +48 -193
  72. data/lib/pry/plugins.rb +2 -2
  73. data/lib/pry/pry_class.rb +193 -104
  74. data/lib/pry/pry_instance.rb +154 -152
  75. data/lib/pry/rbx_method.rb +13 -0
  76. data/lib/pry/rbx_path.rb +1 -1
  77. data/lib/pry/repl.rb +14 -17
  78. data/lib/pry/repl_file_loader.rb +3 -8
  79. data/lib/pry/rubygem.rb +3 -3
  80. data/lib/pry/terminal.rb +3 -4
  81. data/lib/pry/test/helper.rb +11 -6
  82. data/lib/pry/version.rb +1 -1
  83. data/lib/pry/wrapped_module.rb +56 -49
  84. data/man/pry.1 +195 -0
  85. data/man/pry.1.html +204 -0
  86. data/man/pry.1.ronn +141 -0
  87. data/pry.gemspec +31 -0
  88. data/spec/Procfile +3 -0
  89. data/spec/cli_spec.rb +78 -0
  90. data/spec/code_object_spec.rb +277 -0
  91. data/spec/code_spec.rb +219 -0
  92. data/spec/command_helpers_spec.rb +29 -0
  93. data/spec/command_integration_spec.rb +562 -0
  94. data/spec/command_set_spec.rb +627 -0
  95. data/spec/command_spec.rb +821 -0
  96. data/spec/commands/amend_line_spec.rb +247 -0
  97. data/spec/commands/bang_spec.rb +18 -0
  98. data/spec/commands/cat_spec.rb +164 -0
  99. data/spec/commands/cd_spec.rb +250 -0
  100. data/spec/commands/disable_pry_spec.rb +25 -0
  101. data/spec/commands/edit_spec.rb +725 -0
  102. data/spec/commands/exit_all_spec.rb +27 -0
  103. data/spec/commands/exit_program_spec.rb +19 -0
  104. data/spec/commands/exit_spec.rb +28 -0
  105. data/spec/commands/find_method_spec.rb +70 -0
  106. data/spec/commands/gem_list_spec.rb +26 -0
  107. data/spec/commands/gist_spec.rb +79 -0
  108. data/spec/commands/help_spec.rb +56 -0
  109. data/spec/commands/hist_spec.rb +172 -0
  110. data/spec/commands/jump_to_spec.rb +15 -0
  111. data/spec/commands/ls_spec.rb +189 -0
  112. data/spec/commands/play_spec.rb +136 -0
  113. data/spec/commands/raise_up_spec.rb +56 -0
  114. data/spec/commands/save_file_spec.rb +177 -0
  115. data/spec/commands/show_doc_spec.rb +488 -0
  116. data/spec/commands/show_input_spec.rb +17 -0
  117. data/spec/commands/show_source_spec.rb +760 -0
  118. data/spec/commands/whereami_spec.rb +203 -0
  119. data/spec/completion_spec.rb +221 -0
  120. data/spec/control_d_handler_spec.rb +62 -0
  121. data/spec/documentation_helper_spec.rb +73 -0
  122. data/spec/editor_spec.rb +79 -0
  123. data/spec/exception_whitelist_spec.rb +21 -0
  124. data/spec/fixtures/candidate_helper1.rb +11 -0
  125. data/spec/fixtures/candidate_helper2.rb +8 -0
  126. data/spec/fixtures/example.erb +5 -0
  127. data/spec/fixtures/example_nesting.rb +33 -0
  128. data/spec/fixtures/show_source_doc_examples.rb +15 -0
  129. data/spec/fixtures/testlinkrc +2 -0
  130. data/spec/fixtures/testrc +2 -0
  131. data/spec/fixtures/testrcbad +2 -0
  132. data/spec/fixtures/whereami_helper.rb +6 -0
  133. data/spec/helper.rb +35 -0
  134. data/spec/helpers/bacon.rb +86 -0
  135. data/spec/helpers/mock_pry.rb +44 -0
  136. data/spec/helpers/repl_tester.rb +112 -0
  137. data/spec/helpers/table_spec.rb +105 -0
  138. data/spec/history_array_spec.rb +67 -0
  139. data/spec/hooks_spec.rb +522 -0
  140. data/spec/indent_spec.rb +301 -0
  141. data/spec/method_spec.rb +482 -0
  142. data/spec/prompt_spec.rb +61 -0
  143. data/spec/pry_defaults_spec.rb +420 -0
  144. data/spec/pry_history_spec.rb +69 -0
  145. data/spec/pry_output_spec.rb +95 -0
  146. data/spec/pry_repl_spec.rb +86 -0
  147. data/spec/pry_spec.rb +394 -0
  148. data/spec/pryrc_spec.rb +97 -0
  149. data/spec/run_command_spec.rb +25 -0
  150. data/spec/sticky_locals_spec.rb +147 -0
  151. data/spec/syntax_checking_spec.rb +81 -0
  152. data/spec/wrapped_module_spec.rb +261 -0
  153. data/wiki/Customizing-pry.md +397 -0
  154. data/wiki/Home.md +4 -0
  155. metadata +272 -61
  156. checksums.yaml +0 -7
  157. data/CHANGELOG.md +0 -714
  158. data/lib/pry/code/code_file.rb +0 -103
  159. data/lib/pry/color_printer.rb +0 -55
  160. data/lib/pry/commands/change_inspector.rb +0 -27
  161. data/lib/pry/commands/change_prompt.rb +0 -26
  162. data/lib/pry/commands/list_inspectors.rb +0 -35
  163. data/lib/pry/commands/list_prompts.rb +0 -35
  164. data/lib/pry/commands/ls/constants.rb +0 -47
  165. data/lib/pry/commands/ls/formatter.rb +0 -49
  166. data/lib/pry/commands/ls/globals.rb +0 -48
  167. data/lib/pry/commands/ls/grep.rb +0 -21
  168. data/lib/pry/commands/ls/instance_vars.rb +0 -39
  169. data/lib/pry/commands/ls/interrogatable.rb +0 -18
  170. data/lib/pry/commands/ls/jruby_hacks.rb +0 -49
  171. data/lib/pry/commands/ls/local_names.rb +0 -35
  172. data/lib/pry/commands/ls/local_vars.rb +0 -39
  173. data/lib/pry/commands/ls/ls_entity.rb +0 -70
  174. data/lib/pry/commands/ls/methods.rb +0 -57
  175. data/lib/pry/commands/ls/methods_helper.rb +0 -46
  176. data/lib/pry/commands/ls/self_methods.rb +0 -32
  177. data/lib/pry/commands/watch_expression.rb +0 -105
  178. data/lib/pry/commands/watch_expression/expression.rb +0 -38
  179. data/lib/pry/config/behavior.rb +0 -139
  180. data/lib/pry/config/convenience.rb +0 -25
  181. data/lib/pry/config/default.rb +0 -161
  182. data/lib/pry/exceptions.rb +0 -78
  183. data/lib/pry/input_completer.rb +0 -242
  184. data/lib/pry/input_lock.rb +0 -132
  185. data/lib/pry/inspector.rb +0 -27
  186. data/lib/pry/last_exception.rb +0 -61
  187. data/lib/pry/object_path.rb +0 -82
  188. data/lib/pry/output.rb +0 -50
  189. data/lib/pry/prompt.rb +0 -26
@@ -0,0 +1,13 @@
1
+ class Pry
2
+ module RbxMethod
3
+ private
4
+
5
+ def core_code
6
+ MethodSource.source_helper(source_location)
7
+ end
8
+
9
+ def core_doc
10
+ MethodSource.comment_helper(source_location)
11
+ end
12
+ end
13
+ end
@@ -2,7 +2,7 @@ class Pry
2
2
  module RbxPath
3
3
  module_function
4
4
  def is_core_path?(path)
5
- Pry::Helpers::BaseHelpers.rbx? && (path.start_with?("kernel") || path.start_with?("lib")) && File.exist?(convert_path_to_full(path))
5
+ path.start_with?("kernel") || path.start_with?("lib")
6
6
  end
7
7
 
8
8
  def convert_path_to_full(path)
@@ -35,7 +35,7 @@ class Pry
35
35
  # thrown with it.
36
36
  def start
37
37
  prologue
38
- Pry::InputLock.for(:all).with_ownership { repl }
38
+ repl
39
39
  ensure
40
40
  epilogue
41
41
  end
@@ -48,7 +48,7 @@ class Pry
48
48
  pry.exec_hook :before_session, pry.output, pry.current_binding, pry
49
49
 
50
50
  # Clear the line before starting Pry. This fixes issue #566.
51
- if pry.config.correct_indent
51
+ if Pry.config.correct_indent
52
52
  Kernel.print Pry::Helpers::BaseHelpers.windows_ansi? ? "\e[0F" : "\e[0G"
53
53
  end
54
54
  end
@@ -93,18 +93,18 @@ class Pry
93
93
  def read
94
94
  @indent.reset if pry.eval_string.empty?
95
95
  current_prompt = pry.select_prompt
96
- indentation = pry.config.auto_indent ? @indent.current_prefix : ''
96
+ indentation = Pry.config.auto_indent ? @indent.current_prefix : ''
97
97
 
98
98
  val = read_line("#{current_prompt}#{indentation}")
99
99
 
100
100
  # Return nil for EOF, :no_more_input for error, or :control_c for <Ctrl-C>
101
101
  return val unless String === val
102
102
 
103
- if pry.config.auto_indent
103
+ if Pry.config.auto_indent
104
104
  original_val = "#{indentation}#{val}"
105
105
  indented_val = @indent.indent(val)
106
106
 
107
- if output.tty? && pry.config.correct_indent && Pry::Helpers::BaseHelpers.use_ansi_codes?
107
+ if output.tty? && @indent.should_correct_indentation?
108
108
  output.print @indent.correct_indentation(
109
109
  current_prompt, indented_val,
110
110
  original_val.length - indented_val.length
@@ -128,7 +128,7 @@ class Pry
128
128
  begin
129
129
  yield
130
130
  rescue EOFError
131
- pry.config.input = Pry.config.input
131
+ pry.input = Pry.config.input
132
132
  if !should_retry
133
133
  output.puts "Error: Pry ran out of things to read from! " \
134
134
  "Attempting to break out of REPL."
@@ -179,24 +179,21 @@ class Pry
179
179
  end
180
180
  end
181
181
 
182
- if defined?(Readline) and input == Readline
183
- input_readline(current_prompt, false) # false since we'll add it manually
182
+ if input == Readline
183
+ if !$stdout.tty? && $stdin.tty? && !Pry::Helpers::BaseHelpers.windows?
184
+ Readline.output = File.open('/dev/tty', 'w')
185
+ end
186
+ input.readline(current_prompt, false) # false since we'll add it manually
184
187
  elsif defined? Coolline and input.is_a? Coolline
185
- input_readline(current_prompt)
188
+ input.readline(current_prompt)
186
189
  else
187
190
  if input.method(:readline).arity == 1
188
- input_readline(current_prompt)
191
+ input.readline(current_prompt)
189
192
  else
190
- input_readline
193
+ input.readline
191
194
  end
192
195
  end
193
196
  end
194
197
  end
195
-
196
- def input_readline(*args)
197
- Pry::InputLock.for(:all).interruptible_region do
198
- input.readline(*args)
199
- end
200
- end
201
198
  end
202
199
  end
@@ -23,9 +23,9 @@ class Pry
23
23
  # and use the regular print and exception handlers.
24
24
  # @param [Pry] _pry_ the Pry instance to make interactive.
25
25
  def interactive_mode(_pry_)
26
- _pry_.config.input = Pry.config.input
27
- _pry_.config.print = Pry.config.print
28
- _pry_.config.exception_handler = Pry.config.exception_handler
26
+ _pry_.input = Pry.config.input
27
+ _pry_.print = Pry.config.print
28
+ _pry_.exception_handler = Pry.config.exception_handler
29
29
  Pry::REPL.new(_pry_).start
30
30
  end
31
31
 
@@ -44,11 +44,6 @@ class Pry
44
44
  content.lines.each do |line|
45
45
  break unless _pry_.eval line, :generated => true
46
46
  end
47
-
48
- unless _pry_.eval_string.empty?
49
- _pry_.output.puts "#{_pry_.eval_string}...exception encountered, going interactive!"
50
- interactive_mode(_pry_)
51
- end
52
47
  end
53
48
 
54
49
  # Define a few extra commands useful for flipping back & forth
@@ -23,7 +23,7 @@ class Pry
23
23
  Gem.source_index.find_name(name)
24
24
  end
25
25
 
26
- first_spec = specs.sort_by{ |spec| Gem::Version.new(spec.version) }.last
26
+ first_spec = specs.sort_by{ |spec| Gem::Version.new(spec.version) }.first
27
27
 
28
28
  first_spec or raise CommandError, "Gem `#{name}` not found"
29
29
  end
@@ -69,10 +69,10 @@ class Pry
69
69
  installer.install(name)
70
70
  rescue Errno::EACCES
71
71
  raise CommandError,
72
- "Insufficient permissions to install #{ Pry::Helpers::Text.green(name) }."
72
+ "Insufficient permissions to install #{ text.green(name) }."
73
73
  rescue Gem::GemNotFoundException
74
74
  raise CommandError,
75
- "Gem #{ Pry::Helpers::Text.green(name) } not found. Aborting installation."
75
+ "Gem #{ text.green(name) } not found. Aborting installation."
76
76
  else
77
77
  Gem.refresh
78
78
  end
@@ -5,7 +5,7 @@ class Pry::Terminal
5
5
  # If the window size cannot be determined, return nil.
6
6
  def screen_size
7
7
  rows, cols = actual_screen_size
8
- if rows.to_i != 0 && cols.to_i != 0
8
+ if rows && cols
9
9
  [rows.to_i, cols.to_i]
10
10
  else
11
11
  nil
@@ -44,8 +44,7 @@ class Pry::Terminal
44
44
  require 'io/console'
45
45
  $stdout.winsize if $stdout.tty? and $stdout.respond_to?(:winsize)
46
46
  rescue LoadError
47
- # They probably don't have the io/console stdlib or the io-console gem.
48
- # We'll keep trying.
47
+ # They're probably on 1.8 without the io-console gem. We'll keep trying.
49
48
  end
50
49
 
51
50
  def screen_size_according_to_env
@@ -54,7 +53,7 @@ class Pry::Terminal
54
53
  end
55
54
 
56
55
  def screen_size_according_to_readline
57
- if defined?(Readline) && Readline.respond_to?(:get_screen_size)
56
+ if Readline.respond_to?(:get_screen_size)
58
57
  size = Readline.get_screen_size
59
58
  size if nonzero_column?(size)
60
59
  end
@@ -7,8 +7,8 @@ class << Pry
7
7
  def reset_defaults
8
8
  orig_reset_defaults
9
9
 
10
- Pry.config.color = false
11
- Pry.config.pager = false
10
+ Pry.color = false
11
+ Pry.pager = false
12
12
  Pry.config.should_load_rc = false
13
13
  Pry.config.should_load_local_rc= false
14
14
  Pry.config.should_load_plugins = false
@@ -47,6 +47,10 @@ module PryTestHelpers
47
47
  end
48
48
  end
49
49
 
50
+ def mri18_and_no_real_source_location?
51
+ Pry::Helpers::BaseHelpers.mri_18? && !(Method.instance_method(:source_location).owner == Method)
52
+ end
53
+
50
54
  # Open a temp file and yield it to the block, closing it after
51
55
  # @return [String] The path of the temp file
52
56
  def temp_file(ext='.rb')
@@ -63,15 +67,16 @@ module PryTestHelpers
63
67
 
64
68
  def mock_command(cmd, args=[], opts={})
65
69
  output = StringIO.new
66
- pry = Pry.new(output: output)
67
- ret = cmd.new(opts.merge(pry_instance: pry, :output => output)).call_safely(*args)
70
+ ret = cmd.new(opts.merge(:output => output)).call_safely(*args)
68
71
  Struct.new(:output, :return).new(output.string, ret)
69
72
  end
70
73
 
71
74
  def mock_exception(*mock_backtrace)
72
- StandardError.new.tap do |e|
73
- e.define_singleton_method(:backtrace) { mock_backtrace }
75
+ e = StandardError.new("mock exception")
76
+ (class << e; self; end).class_eval do
77
+ define_method(:backtrace) { mock_backtrace }
74
78
  end
79
+ e
75
80
  end
76
81
  end
77
82
 
@@ -1,3 +1,3 @@
1
1
  class Pry
2
- VERSION = "0.10.2"
2
+ VERSION = "1.0.0.pre1"
3
3
  end
@@ -66,12 +66,28 @@ class Pry
66
66
  end
67
67
 
68
68
  # Returns an array of the names of the constants accessible in the wrapped
69
- # module. This avoids the problem of accidentally calling the singleton
70
- # method `Module.constants`.
69
+ # module. This provides a consistent interface between 1.8 and 1.9 and also
70
+ # avoids the problem of accidentally calling the singleton method
71
+ # `Module.constants`.
71
72
  # @param [Boolean] inherit Include the names of constants from included
72
73
  # modules?
73
74
  def constants(inherit = true)
74
- Module.instance_method(:constants).bind(@wrapped).call(inherit)
75
+ method = Module.instance_method(:constants).bind(@wrapped)
76
+
77
+ # If we're on 1.8, we have to manually remove ancestors' constants. If
78
+ # we're on 1.9, though, it's better to use the built-in `inherit` param,
79
+ # since it doesn't do things like incorrectly remove Pry::Config.
80
+ if method.arity == 0
81
+ consts = method.call
82
+ if !inherit
83
+ ancestors_ = Pry::Method.safe_send(@wrapped, :ancestors)
84
+ consts -= (ancestors_ - [@wrapped]).map(&:constants).flatten
85
+ end
86
+ else
87
+ consts = method.call(inherit)
88
+ end
89
+
90
+ consts
75
91
  end
76
92
 
77
93
  # The prefix that would appear before methods defined on this class.
@@ -105,15 +121,7 @@ class Pry
105
121
  # Is this a singleton class?
106
122
  # @return [Boolean]
107
123
  def singleton_class?
108
- if Pry::Method.safe_send(wrapped, :respond_to?, :singleton_class?)
109
- Pry::Method.safe_send(wrapped, :singleton_class?)
110
- elsif defined?(Rubinius)
111
- # https://github.com/rubinius/rubinius/commit/2e71722dba53d1a92c54d5e3968d64d1042486fe singleton_class? added 30 Jul 2014
112
- # https://github.com/rubinius/rubinius/commit/4310f6b2ef3c8fc88135affe697db4e29e4621c4 has been around since 2011
113
- !!Rubinius::Type.singleton_class_object(wrapped)
114
- else
115
- wrapped != Pry::Method.safe_send(wrapped, :ancestors).first
116
- end
124
+ wrapped != Pry::Method.safe_send(wrapped, :ancestors).first
117
125
  end
118
126
 
119
127
  # Is this strictly a module? (does not match classes)
@@ -247,7 +255,7 @@ class Pry
247
255
  # @return [Enumerator, Array] on JRuby 1.9 and higher returns Array, on
248
256
  # other rubies returns Enumerator
249
257
  def candidates
250
- enum = Enumerator.new do |y|
258
+ enum = generator.new do |y|
251
259
  (0...number_of_candidates).each do |num|
252
260
  y.yield candidate(num)
253
261
  end
@@ -280,17 +288,24 @@ class Pry
280
288
 
281
289
  private
282
290
 
283
- # @return [Pry::WrappedModule::Candidate] The candidate with the
284
- # highest rank, that is the 'monkey patch' of this module with the
285
- # highest number of methods, which contains a source code line that
286
- # defines the module. It is considered the 'canonical' definition
287
- # for the module. In the absense of a suitable candidate, the
288
- # candidate of rank 0 will be returned, or a CommandError raised if
289
- # there are no candidates at all.
291
+ # Ruby 1.8 doesn't support `Enumerator` (it's called Generator instead)
292
+ #
293
+ # @return [Object] Return the appropriate generator class.
294
+ def generator
295
+ @generator ||= if defined?(Enumerator)
296
+ Enumerator
297
+ else
298
+ require 'generator'
299
+ Generator
300
+ end
301
+ end
302
+
303
+ # @return [Pry::WrappedModule::Candidate] The candidate of rank 0,
304
+ # that is the 'monkey patch' of this module with the highest
305
+ # number of methods. It is considered the 'canonical' definition
306
+ # for the module.
290
307
  def primary_candidate
291
- @primary_candidate ||= candidates.find { |c| c.file } ||
292
- # This will raise an exception if there is no candidate at all.
293
- candidate(0)
308
+ @primary_candidate ||= candidate(0)
294
309
  end
295
310
 
296
311
  # @return [Array<Array<Pry::Method>>] The array of `Pry::Method` objects,
@@ -312,12 +327,7 @@ class Pry
312
327
 
313
328
  ims = all_relevant_methods_for(wrapped)
314
329
  @all_source_locations_by_popularity = ims.group_by { |v| Array(v.source_location).first }.
315
- sort_by do |path, methods|
316
- expanded = File.expand_path(path)
317
- load_order = $LOADED_FEATURES.index{ |file| expanded.end_with?(file) }
318
-
319
- [-methods.size, load_order || (1.0 / 0.0)]
320
- end
330
+ sort_by { |k, v| -v.size }
321
331
  end
322
332
 
323
333
  # We only want methods that have a non-nil `source_location`. We also
@@ -325,33 +335,30 @@ class Pry
325
335
  # (i.e we skip `__class_init__` because it's an odd rbx specific thing that causes tests to fail.)
326
336
  # @return [Array<Pry::Method>]
327
337
  def all_relevant_methods_for(mod)
328
- methods = all_methods_for(mod).select(&:source_location).
338
+ all_methods_for(mod).select(&:source_location).
329
339
  reject{ |x| x.name == '__class_init__' || method_defined_by_forwardable_module?(x) }
330
-
331
- return methods unless methods.empty?
332
-
333
- safe_send(mod, :constants).map do |const_name|
334
- if const = nested_module?(mod, const_name)
335
- all_relevant_methods_for(const)
336
- else
337
- []
338
- end
339
- end.flatten
340
340
  end
341
341
 
342
342
  # Return all methods (instance methods and class methods) for a
343
343
  # given module.
344
344
  # @return [Array<Pry::Method>]
345
345
  def all_methods_for(mod)
346
- Pry::Method.all_from_obj(mod, false) + Pry::Method.all_from_class(mod, false)
347
- end
348
-
349
- def nested_module?(parent, name)
350
- return if safe_send(parent, :autoload?, name)
351
- child = safe_send(parent, :const_get, name)
352
- return unless Module === child
353
- return unless safe_send(child, :name) == "#{safe_send(parent, :name)}::#{name}"
354
- child
346
+ all_from_common(mod, :instance_method) + all_from_common(mod, :method)
347
+ end
348
+
349
+ # FIXME: a variant of this method is also found in Pry::Method
350
+ def all_from_common(mod, method_type)
351
+ %w(public protected private).map do |visibility|
352
+ safe_send(mod, :"#{visibility}_#{method_type}s", false).select do |method_name|
353
+ if method_type == :method
354
+ safe_send(mod, method_type, method_name).owner == class << mod; self; end
355
+ else
356
+ safe_send(mod, method_type, method_name).owner == mod
357
+ end
358
+ end.map do |method_name|
359
+ Pry::Method.new(safe_send(mod, method_type, method_name), :visibility => visibility.to_sym)
360
+ end
361
+ end.flatten
355
362
  end
356
363
 
357
364
  # Detect methods that are defined with `def_delegator` from the Forwardable
@@ -0,0 +1,195 @@
1
+ .\" generated with Ronn/v0.7.3
2
+ .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
+ .
4
+ .TH "PRY" "1" "November 2011" "" ""
5
+ .
6
+ .SH "NAME"
7
+ \fBPRY\fR \- A Reference to the PRY repl\.
8
+ .
9
+ .SH "Synopsis"
10
+ \fBpry\fR [\fB\-\-version\fR] [\fB\-\-exec\fR] [\fB\-\-no\-pager\fR] [\fB\-\-no\-history\fR] [\fB\-\-no\-color\fR] [\fB\-f\fR] [\fB\-\-no\-plugins\fR] [\fB\-\-installed\-plugins\fR] [\fB\-\-simple\-prompt\fR] [\fB\-\-require\fR \fIfile\fR] [\fB\-I\fR] [\fB\-\-context\fR] [\fB\-\-help\fR]
11
+ .
12
+ .SH "DESCRIPTION"
13
+ Pry is a powerful alternative to the standard IRB shell for Ruby\. It is written from scratch to provide a number of advanced features\.
14
+ .
15
+ .SH "HOMEPAGE"
16
+ http://pry\.github\.com/
17
+ .
18
+ .SH "OPTIONS"
19
+ .
20
+ .TP
21
+ \fB\-v \-\-version\fR
22
+ Prints the version of Pry\.
23
+ .
24
+ .TP
25
+ \fB\-e \-\-exec\fR
26
+ Executes argument in context before the session starts\.
27
+ .
28
+ .TP
29
+ \fB\-\-no\-pager\fR
30
+ Disable pager for long output\.
31
+ .
32
+ .TP
33
+ \fB\-\-no\-history\fR
34
+ Disable history loading\.
35
+ .
36
+ .TP
37
+ \fB\-\-no\-color\fR
38
+ Disable syntax highlighting for session\.
39
+ .
40
+ .TP
41
+ \fB\-f\fR
42
+ Prevent loading of ~/\.pryrc for session\.
43
+ .
44
+ .TP
45
+ \fB\-\-no\-plugins\fR
46
+ Supress loading of plugins\.
47
+ .
48
+ .TP
49
+ \fB\-\-installed\-plugins\fR
50
+ List installed plugins\.
51
+ .
52
+ .TP
53
+ \fB\-\-simple\-prompt\fR
54
+ Enable simple prompt mode (eg, >>)\.
55
+ .
56
+ .TP
57
+ \fB\-r \-\-require\fR
58
+ Require a ruby script at startup\.
59
+ .
60
+ .TP
61
+ \fB\-I\fR
62
+ Add a path to the $LOAD_PATH
63
+ .
64
+ .TP
65
+ \fB\-c \-\-context\fR
66
+ Start the session in the specified context\. Equivalent to \fBcontext\.pry\fR in a session\.
67
+ .
68
+ .SH "FILES"
69
+ ~/\.pryrc Personal pry initialization
70
+ .
71
+ .SH "EXAMPLES"
72
+ .
73
+ .SS "Basic Usage"
74
+ .
75
+ .nf
76
+
77
+ $ pry
78
+ [1] pry(main)>4 + 5
79
+ => 9
80
+ [2] pry(main)> def hello_world
81
+ [2] pry(main)* puts "Hello, World!"
82
+ [2] pry(main)* end
83
+ => nil
84
+ [3] pry(main)> hello_world
85
+ Hello, World!
86
+ => nil
87
+ .
88
+ .fi
89
+ .
90
+ .SS "Command Line Interaction"
91
+ Prefix any command you want your shell to execute with a period and pry will return the results from your shell\.
92
+ .
93
+ .IP "" 4
94
+ .
95
+ .nf
96
+
97
+ [1] pry(main)> \.date
98
+ Fri Nov 11 09:52:07 EST 2011
99
+ .
100
+ .fi
101
+ .
102
+ .IP "" 0
103
+ .
104
+ .P
105
+ On the command line enter \fBshell\-mode\fR to incorporate the current working directory into the Pry prompt\.
106
+ .
107
+ .IP "" 4
108
+ .
109
+ .nf
110
+
111
+ pry(main)> shell\-mode
112
+ pry main:/Users/john/ruby/projects/pry $ \.cd \.\.
113
+ pry main:/Users/john/ruby/projects $ \.cd ~
114
+ pry main:/Users/john $ \.pwd
115
+ /Users/john
116
+ pry main:/Users/john $ shell\-mode
117
+ pry(main)>
118
+ .
119
+ .fi
120
+ .
121
+ .IP "" 0
122
+ .
123
+ .SS "State Navigation"
124
+ The cd command is used to move into a new object (or scope) inside a Pry session\. When inside the new scope it becomes the self for the session and all commands and methods will operate on this new self\.
125
+ .
126
+ .IP "" 4
127
+ .
128
+ .nf
129
+
130
+ pry(main)> self
131
+ => main
132
+ pry(main)> cd Pry
133
+ pry(Pry):1> self
134
+ => Pry
135
+ pry(Pry):1> cd \.\.
136
+ pry(main)>
137
+ .
138
+ .fi
139
+ .
140
+ .IP "" 0
141
+ .
142
+ .P
143
+ The ls command is essentially a unified wrapper to a number of Ruby\'s introspection mechanisms, including (but not limited to) the following methods: methods, instance_variables, constants, local_variables, instance_methods, class_variables and all the various permutations thereof\.
144
+ .
145
+ .P
146
+ By default typing ls will return a list of just the local and instance variables available in the current context\.
147
+ .
148
+ .IP "\(bu" 4
149
+ The \-M option selects public instance methods (if available)\.
150
+ .
151
+ .IP "\(bu" 4
152
+ The \-m option selects public methods\.
153
+ .
154
+ .IP "\(bu" 4
155
+ The \-c option selects constants\.
156
+ .
157
+ .IP "\(bu" 4
158
+ The \-i option select just instance variables\.
159
+ .
160
+ .IP "\(bu" 4
161
+ The \-l option selects just local variables\.
162
+ .
163
+ .IP "\(bu" 4
164
+ The \-s option modifies the \-c and \-m and \-M options to go up the superclass chain (excluding Object)\.
165
+ .
166
+ .IP "\(bu" 4
167
+ The \-\-grep REGEX prunes the list to items that match the regex\.
168
+ .
169
+ .IP "" 0
170
+ .
171
+ .SS "Source Browsing"
172
+ Simply typing show\-method method_name will pull the source for the method and display it with syntax highlighting\. You can also look up the source for multiple methods at the same time, by typing show\-method method1 method2\. As a convenience, Pry looks up both instance methods and class methods using this syntax, with priority given to instance methods\.
173
+ .
174
+ .IP "" 4
175
+ .
176
+ .nf
177
+
178
+ pry(Pry):1> show\-method rep
179
+
180
+ From: /Users/john/ruby/projects/pry/lib/pry/pry_instance\.rb @ line 191:
181
+ Number of lines: 6
182
+
183
+ def rep(target=TOPLEVEL_BINDING)
184
+ target = Pry\.binding_for(target)
185
+ result = re(target)
186
+
187
+ show_result(result) if should_print?
188
+ end
189
+ .
190
+ .fi
191
+ .
192
+ .IP "" 0
193
+ .
194
+ .SH "AUTHORS"
195
+ Pry is primarily the work of John Mair (banisterfiend)