pry 0.9.9.6pre2-java → 0.9.10-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. data/CHANGELOG +41 -0
  2. data/CONTRIBUTORS +27 -26
  3. data/README.markdown +4 -4
  4. data/Rakefile +2 -2
  5. data/lib/pry.rb +25 -19
  6. data/lib/pry/cli.rb +31 -10
  7. data/lib/pry/code.rb +41 -83
  8. data/lib/pry/command.rb +87 -76
  9. data/lib/pry/command_set.rb +13 -20
  10. data/lib/pry/completion.rb +139 -121
  11. data/lib/pry/config.rb +4 -0
  12. data/lib/pry/core_extensions.rb +88 -31
  13. data/lib/pry/default_commands/cd.rb +31 -8
  14. data/lib/pry/default_commands/context.rb +4 -58
  15. data/lib/pry/default_commands/easter_eggs.rb +1 -1
  16. data/lib/pry/default_commands/editing.rb +21 -14
  17. data/lib/pry/default_commands/find_method.rb +5 -7
  18. data/lib/pry/default_commands/gist.rb +187 -0
  19. data/lib/pry/default_commands/hist.rb +6 -6
  20. data/lib/pry/default_commands/input_and_output.rb +73 -129
  21. data/lib/pry/default_commands/introspection.rb +107 -52
  22. data/lib/pry/default_commands/ls.rb +1 -1
  23. data/lib/pry/default_commands/misc.rb +0 -5
  24. data/lib/pry/default_commands/whereami.rb +92 -0
  25. data/lib/pry/helpers/base_helpers.rb +6 -1
  26. data/lib/pry/helpers/command_helpers.rb +30 -9
  27. data/lib/pry/helpers/documentation_helpers.rb +7 -7
  28. data/lib/pry/helpers/options_helpers.rb +1 -1
  29. data/lib/pry/helpers/text.rb +7 -9
  30. data/lib/pry/history.rb +15 -2
  31. data/lib/pry/hooks.rb +1 -1
  32. data/lib/pry/indent.rb +17 -10
  33. data/lib/pry/method.rb +35 -19
  34. data/lib/pry/module_candidate.rb +130 -0
  35. data/lib/pry/pry_class.rb +54 -22
  36. data/lib/pry/pry_instance.rb +71 -14
  37. data/lib/pry/repl_file_loader.rb +80 -0
  38. data/lib/pry/version.rb +1 -1
  39. data/lib/pry/wrapped_module.rb +121 -142
  40. data/pry.gemspec +13 -13
  41. data/test/candidate_helper1.rb +11 -0
  42. data/test/candidate_helper2.rb +8 -0
  43. data/test/helper.rb +16 -0
  44. data/test/test_code.rb +1 -1
  45. data/test/test_command.rb +364 -270
  46. data/test/test_command_integration.rb +235 -267
  47. data/test/test_completion.rb +36 -0
  48. data/test/test_control_d_handler.rb +45 -0
  49. data/test/test_default_commands/example.erb +5 -0
  50. data/test/test_default_commands/test_cd.rb +316 -11
  51. data/test/test_default_commands/test_context.rb +143 -192
  52. data/test/test_default_commands/test_documentation.rb +81 -14
  53. data/test/test_default_commands/test_find_method.rb +10 -2
  54. data/test/test_default_commands/test_input.rb +102 -111
  55. data/test/test_default_commands/test_introspection.rb +17 -12
  56. data/test/test_default_commands/test_ls.rb +8 -6
  57. data/test/test_default_commands/test_shell.rb +18 -15
  58. data/test/test_default_commands/test_show_source.rb +170 -44
  59. data/test/test_exception_whitelist.rb +6 -2
  60. data/test/test_hooks.rb +32 -0
  61. data/test/test_input_stack.rb +19 -16
  62. data/test/test_method.rb +0 -4
  63. data/test/test_prompt.rb +60 -0
  64. data/test/test_pry.rb +23 -31
  65. data/test/test_pry_defaults.rb +75 -57
  66. data/test/test_syntax_checking.rb +12 -11
  67. data/test/test_wrapped_module.rb +103 -0
  68. metadata +72 -26
@@ -68,15 +68,12 @@ class Pry
68
68
  end
69
69
 
70
70
  # Create a new command with the given properties.
71
- #
72
- # @param String/Regex match the thing that triggers this command
73
- # @param String description the description to appear in {help}
74
- # @param Hash options behavioural options (@see {Pry::CommandSet#command})
75
- # @param Module helpers a module of helper functions to be included.
76
- # @param Proc &block (optional, a block, used for BlockCommands)
77
- #
78
- # @return Class (a subclass of Pry::Command)
79
- #
71
+ # @param [String, Regex] match The thing that triggers this command
72
+ # @param [String] description The description to appear in `help`
73
+ # @param [Hash] options Behavioral options (see {Pry::CommandSet#command})
74
+ # @param [Module] helpers A module of helper functions to be included.
75
+ # @yield optional, used for BlockCommands
76
+ # @return [Class] (a subclass of {Pry::Command})
80
77
  def subclass(match, description, options, helpers, &block)
81
78
  klass = Class.new(self)
82
79
  klass.send(:include, helpers)
@@ -88,9 +85,8 @@ class Pry
88
85
  end
89
86
 
90
87
  # Should this command be called for the given line?
91
- #
92
- # @param String a line input at the REPL
93
- # @return Boolean
88
+ # @param [String] val A line input at the REPL
89
+ # @return [Boolean]
94
90
  def matches?(val)
95
91
  command_regex =~ val
96
92
  end
@@ -109,8 +105,8 @@ class Pry
109
105
  # /\.*(.*)/.match_score("...foo") #=> 3
110
106
  # 'hi'.match_score("hi there") #=> 2
111
107
  #
112
- # @param String a line input at the REPL
113
- # @return Fixnum
108
+ # @param [String] val A line input at the REPL
109
+ # @return [Fixnum]
114
110
  def match_score(val)
115
111
  if command_regex =~ val
116
112
  Regexp.last_match.size > 1 ? Regexp.last_match.begin(1) : Regexp.last_match.end(0)
@@ -147,25 +143,26 @@ class Pry
147
143
  # This is usually auto-generated from directory naming, but it can be
148
144
  # manually overridden if necessary.
149
145
  def group(name=nil)
150
- @group = name if name
151
- @group ||=(
152
- case Pry::Method(block).source_file
153
- when %r{/pry/.*_commands/(.*).rb}
154
- $1.capitalize.gsub(/_/, " ")
155
- when %r{(pry-[\w_]+)-([\d\.]+)}
156
- name, version = $1, $2
157
- "#{name.to_s} (v#{version.to_s})"
158
- when /pryrc/
159
- "~/.pryrc"
160
- else
161
- "(other)"
162
- end
163
- )
146
+ @group ||= if name
147
+ name
148
+ else
149
+ case Pry::Method(block).source_file
150
+ when %r{/pry/.*_commands/(.*).rb}
151
+ $1.capitalize.gsub(/_/, " ")
152
+ when %r{(pry-\w+)-([\d\.]+([\w\d\.]+)?)}
153
+ name, version = $1, $2
154
+ "#{name.to_s} (v#{version.to_s})"
155
+ when /pryrc/
156
+ "~/.pryrc"
157
+ else
158
+ "(other)"
159
+ end
160
+ end
164
161
  end
165
162
  end
166
163
 
167
164
  # Properties of one execution of a command (passed by {Pry#run_command} as a hash of
168
- # context and expanded in {#initialize}
165
+ # context and expanded in `#initialize`
169
166
  attr_accessor :output
170
167
  attr_accessor :target
171
168
  attr_accessor :captures
@@ -214,8 +211,7 @@ class Pry
214
211
 
215
212
 
216
213
  # Instantiate a command, in preparation for calling it.
217
- #
218
- # @param Hash context The runtime context to use with this command.
214
+ # @param [Hash] context The runtime context to use with this command.
219
215
  def initialize(context={})
220
216
  self.context = context
221
217
  self.target = context[:target]
@@ -225,9 +221,20 @@ class Pry
225
221
  self._pry_ = context[:pry_instance]
226
222
  end
227
223
 
228
- # The value of {self} inside the {target} binding.
224
+ # @return [Object] The value of `self` inside the `target` binding.
229
225
  def target_self; target.eval('self'); end
230
226
 
227
+ # @return [Hash] Pry commands can store arbitrary state
228
+ # here. This state persists between subsequent command invocations.
229
+ # All state saved here is unique to the command, it does not
230
+ # need to be namespaced.
231
+ # @example
232
+ # state.my_state = "my state" # this will not conflict with any
233
+ # # `state.my_state` used in another command.
234
+ def state
235
+ _pry_.command_state[match] ||= OpenStruct.new
236
+ end
237
+
231
238
  # Revaluate the string (str) and perform interpolation.
232
239
  # @param [String] str The string to reevaluate with interpolation.
233
240
  #
@@ -244,8 +251,6 @@ class Pry
244
251
 
245
252
  # Display a warning if a command collides with a local/method in
246
253
  # the current scope.
247
- # @param [String] command_name_match The name of the colliding command.
248
- # @param [Binding] target The current binding context.
249
254
  def check_for_command_collision(command_match, arg_string)
250
255
  collision_type = target.eval("defined?(#{command_match})")
251
256
  collision_type ||= 'local-variable' if arg_string.match(%r{\A\s*[-+*/%&|^]*=})
@@ -257,15 +262,20 @@ class Pry
257
262
  rescue Pry::RescuableException
258
263
  end
259
264
 
260
- # Extract necessary information from a line that Command.matches? this command.
265
+ # Extract necessary information from a line that Command.matches? this
266
+ # command.
267
+ #
268
+ # Returns an array of four elements:
261
269
  #
262
- # @param String the line of input
263
- # @return [
264
- # String the portion of the line that matched with the Command match
265
- # String a string of all the arguments (i.e. everything but the match)
266
- # Array the captures caught by the command_regex
267
- # Array args the arguments got by splitting the arg_string
268
- # ]
270
+ # ```
271
+ # [String] the portion of the line that matched with the Command match
272
+ # [String] a string of all the arguments (i.e. everything but the match)
273
+ # [Array] the captures caught by the command_regex
274
+ # [Array] the arguments obtained by splitting the arg_string
275
+ # ```
276
+ #
277
+ # @param [String] val The line of input
278
+ # @return [Array]
269
279
  def tokenize(val)
270
280
  val.replace(interpolate_string(val)) if command_options[:interpolate]
271
281
 
@@ -294,9 +304,8 @@ class Pry
294
304
  end
295
305
 
296
306
  # Process a line that Command.matches? this command.
297
- #
298
- # @param String the line to process
299
- # @return Object or Command::VOID_VALUE
307
+ # @param [String] line The line to process
308
+ # @return [Object, Command::VOID_VALUE]
300
309
  def process_line(line)
301
310
  command_match, arg_string, captures, args = tokenize(line)
302
311
 
@@ -316,7 +325,7 @@ class Pry
316
325
  # Note that if we find the '| do' or '| {' we delete this and the
317
326
  # elements following it from `arg_string`.
318
327
  def pass_block(arg_string)
319
- block_index = arg_string.rindex /\| *(?:do|\{)/
328
+ block_index = arg_string.rindex(/\| *(?:do|\{)/)
320
329
 
321
330
  return if !block_index
322
331
 
@@ -338,12 +347,14 @@ class Pry
338
347
 
339
348
  private :pass_block
340
349
 
341
- # Run the command with the given {args}.
350
+ # Run the command with the given `args`.
342
351
  #
343
- # This is a public wrapper around {#call} which ensures all preconditions are met.
352
+ # This is a public wrapper around `#call` which ensures all preconditions
353
+ # are met.
344
354
  #
345
- # @param *[String] the arguments to pass to this command.
346
- # @return Object the return value of the {#call} method, or Command::VOID_VALUE
355
+ # @param [Array<String>] args The arguments to pass to this command.
356
+ # @return [Object] The return value of the `#call` method, or
357
+ # {Command::VOID_VALUE}.
347
358
  def call_safely(*args)
348
359
  unless dependencies_met?
349
360
  gems_needed = Array(command_options[:requires_gem])
@@ -371,10 +382,9 @@ class Pry
371
382
 
372
383
  private
373
384
 
374
- # Run the {#call} method and all the registered hooks.
375
- #
376
- # @param *String the arguments to #{call}
377
- # @return Object the return value from #{call}
385
+ # Run the `#call` method and all the registered hooks.
386
+ # @param [Array<String>] args The arguments to `#call`
387
+ # @return [Object] The return value from `#call`
378
388
  def call_with_hooks(*args)
379
389
  self.class.hooks[:before].each do |block|
380
390
  instance_exec(*args, &block)
@@ -390,10 +400,9 @@ class Pry
390
400
  end
391
401
 
392
402
  # Fix the number of arguments we pass to a block to avoid arity warnings.
393
- #
394
- # @param Number the arity of the block
395
- # @param Array the arguments to pass
396
- # @return Array a (possibly shorter) array of the arguments to pass
403
+ # @param [Fixnum] arity The arity of the block
404
+ # @param [Array] args The arguments to pass
405
+ # @return [Array] A (possibly shorter) array of the arguments to pass
397
406
  def correct_arg_arity(arity, args)
398
407
  case
399
408
  when arity < 0
@@ -417,9 +426,8 @@ class Pry
417
426
  alias_method :opts, :context
418
427
 
419
428
  # Call the block that was registered with this command.
420
- #
421
- # @param *String the arguments passed
422
- # @return Object the return value of the block
429
+ # @param [Array<String>] args The arguments passed
430
+ # @return [Object] The return value of the block
423
431
  def call(*args)
424
432
  instance_exec(*correct_arg_arity(block.arity, args), &block)
425
433
  end
@@ -431,24 +439,26 @@ class Pry
431
439
 
432
440
  # A super-class ofr Commands with structure.
433
441
  #
434
- # This class implements the bare-minimum functionality that a command should have,
435
- # namely a --help switch, and then delegates actual processing to its subclasses.
442
+ # This class implements the bare-minimum functionality that a command should
443
+ # have, namely a --help switch, and then delegates actual processing to its
444
+ # subclasses.
436
445
  #
437
- # Create subclasses using {Pry::CommandSet#create_command}, and override the {options(opt)} method
438
- # to set up an instance of Slop, and the {process} method to actually run the command. If
439
- # necessary, you can also override {setup} which will be called before {options}, for example to
440
- # require any gems your command needs to run, or to set up state.
446
+ # Create subclasses using {Pry::CommandSet#create_command}, and override the
447
+ # `options(opt)` method to set up an instance of Slop, and the `process`
448
+ # method to actually run the command. If necessary, you can also override
449
+ # `setup` which will be called before `options`, for example to require any
450
+ # gems your command needs to run, or to set up state.
441
451
  class ClassCommand < Command
442
452
 
443
453
  attr_accessor :opts
444
454
  attr_accessor :args
445
455
 
446
- # Set up {opts} and {args}, and then call {process}
456
+ # Set up `opts` and `args`, and then call `process`.
447
457
  #
448
458
  # This function will display help if necessary.
449
459
  #
450
- # @param *String the arguments passed
451
- # @return Object the return value of {process} or VOID_VALUE
460
+ # @param [Array<String>] args The arguments passed
461
+ # @return [Object] The return value of `process` or VOID_VALUE
452
462
  def call(*args)
453
463
  setup
454
464
 
@@ -477,7 +487,7 @@ class Pry
477
487
  end
478
488
  end
479
489
 
480
- # A function called just before {options(opt)} as part of {call}.
490
+ # A function called just before `options(opt)` as part of `call`.
481
491
  #
482
492
  # This function can be used to set up any context your command needs to run, for example
483
493
  # requiring gems, or setting default values for options.
@@ -493,7 +503,7 @@ class Pry
493
503
  #
494
504
  # NOTE: please don't do anything side-effecty in the main part of this method,
495
505
  # as it may be called by Pry at any time for introspection reasons. If you need
496
- # to set up default values, use {setup} instead.
506
+ # to set up default values, use `setup` instead.
497
507
  #
498
508
  # @example
499
509
  # def options(opt)
@@ -506,11 +516,12 @@ class Pry
506
516
 
507
517
  # The actual body of your command should go here.
508
518
  #
509
- # The {opts} mehod can be called to get the options that Slop has passed,
510
- # and {args} gives the remaining, unparsed arguments.
519
+ # The `opts` mehod can be called to get the options that Slop has passed,
520
+ # and `args` gives the remaining, unparsed arguments.
511
521
  #
512
- # The return value of this method is discarded unless the command was created
513
- # with :keep_retval => true, in which case it is returned to the repl.
522
+ # The return value of this method is discarded unless the command was
523
+ # created with `:keep_retval => true`, in which case it is returned to the
524
+ # repl.
514
525
  #
515
526
  # @example
516
527
  # def process
@@ -92,7 +92,7 @@ class Pry
92
92
  # @param [String, Regexp] match The start of invocations of this command.
93
93
  # @param [String] description A description of the command.
94
94
  # @param [Hash] options The optional configuration parameters, see {#command}
95
- # @param &Block The class body's definition.
95
+ # @yield The class body's definition.
96
96
  #
97
97
  # @example
98
98
  # Pry::Commands.create_command "echo", "echo's the input", :shellwords => false do
@@ -153,7 +153,7 @@ class Pry
153
153
  end
154
154
 
155
155
  # Add a given command object to this set.
156
- # @param Command the subclass of Pry::Command you wish to add.
156
+ # @param [Command] command The subclass of Pry::Command you wish to add.
157
157
  def add_command(command)
158
158
  commands[command.match] = command
159
159
  end
@@ -208,8 +208,6 @@ class Pry
208
208
  protected :find_command_by_match_or_listing
209
209
 
210
210
  # Aliases a command
211
- # Note that if `desc` parameter is `nil` then the default
212
- # description is used.
213
211
  # @param [String, Regex] match The match of the alias (can be a regex).
214
212
  # @param [String] action The action to be performed (typically
215
213
  # another command).
@@ -242,7 +240,7 @@ class Pry
242
240
 
243
241
  # Rename a command. Accepts either match or listing for the search.
244
242
  #
245
- # @param [String, Regexp] new_name The new match for the command.
243
+ # @param [String, Regexp] new_match The new match for the command.
246
244
  # @param [String, Regexp] search The command's current match or listing.
247
245
  # @param [Hash] options The optional configuration parameters,
248
246
  # accepts the same as the `command` method, but also allows the
@@ -267,8 +265,8 @@ class Pry
267
265
  # Sets or gets the description for a command (replacing the old
268
266
  # description). Returns current description if no description
269
267
  # parameter provided.
270
- # @param [String, Regexp] match The command match.
271
- # @param [String] description The command description.
268
+ # @param [String, Regexp] search The command match.
269
+ # @param [String?] description (nil) The command description.
272
270
  # @example Setting
273
271
  # MyCommands = Pry::CommandSet.new do
274
272
  # desc "help", "help description"
@@ -305,8 +303,7 @@ class Pry
305
303
  end
306
304
 
307
305
  # Find a command that matches the given line
308
- #
309
- # @param [String] the line that may be a command invocation
306
+ # @param [String] val The line that might be a command invocation
310
307
  # @return [Pry::Command, nil]
311
308
  def find_command(val)
312
309
  commands.values.select{ |c| c.matches?(val) }.sort_by{ |c| c.match_score(val) }.last
@@ -314,9 +311,8 @@ class Pry
314
311
  alias_method :[], :find_command
315
312
 
316
313
  # Find the command that the user might be trying to refer to.
317
- #
318
- # @param [String] the user's search.
319
- # @return [Pry::Command, nil]
314
+ # @param [String] search The user's search.
315
+ # @return [Pry::Command?]
320
316
  def find_command_for_help(search)
321
317
  find_command(search) || (begin
322
318
  find_command_by_match_or_listing(search)
@@ -326,19 +322,16 @@ class Pry
326
322
  end
327
323
 
328
324
  # Is the given line a command invocation?
329
- #
330
- # @param [String]
325
+ # @param [String] val
331
326
  # @return [Boolean]
332
327
  def valid_command?(val)
333
328
  !!find_command(val)
334
329
  end
335
330
 
336
331
  # Process the given line to see whether it needs executing as a command.
337
- #
338
- # @param String the line to execute
339
- # @param Hash the context to execute the commands with
340
- # @return CommandSet::Result
341
- #
332
+ # @param [String] val The line to execute
333
+ # @param [Hash] context The context to execute the commands with
334
+ # @return [CommandSet::Result]
342
335
  def process_line(val, context={})
343
336
  if command = find_command(val)
344
337
  context = context.merge(:command_set => self)
@@ -349,7 +342,7 @@ class Pry
349
342
  end
350
343
  end
351
344
 
352
- # @nodoc used for testing
345
+ # @private (used for testing)
353
346
  def run_command(context, match, *args)
354
347
  command = commands[match] or raise NoCommandError.new(match, self)
355
348
  command.new(context).call_safely(*args)
@@ -8,7 +8,7 @@ class Pry
8
8
  module InputCompleter
9
9
 
10
10
  if Readline.respond_to?("basic_word_break_characters=")
11
- Readline.basic_word_break_characters= " \t\n\"\\'`><=;|&{("
11
+ Readline.basic_word_break_characters = " \t\n\"\\'`><=;|&{("
12
12
  end
13
13
 
14
14
  Readline.completion_append_character = nil
@@ -43,146 +43,164 @@ class Pry
43
43
  # @param [Array<String>] commands The array of Pry commands.
44
44
  def self.build_completion_proc(target, commands=[""])
45
45
  proc do |input|
46
- bind = target
47
-
48
- case input
49
- when /^(\/[^\/]*\/)\.([^.]*)$/
50
- # Regexp
51
- receiver = $1
52
- message = Regexp.quote($2)
53
-
54
- candidates = Regexp.instance_methods.collect{|m| m.to_s}
55
- select_message(receiver, message, candidates)
56
-
57
- when /^([^\]]*\])\.([^.]*)$/
58
- # Array
59
- receiver = $1
60
- message = Regexp.quote($2)
61
-
62
- candidates = Array.instance_methods.collect{|m| m.to_s}
63
- select_message(receiver, message, candidates)
64
-
65
- when /^([^\}]*\})\.([^.]*)$/
66
- # Proc or Hash
67
- receiver = $1
68
- message = Regexp.quote($2)
69
-
70
- candidates = Proc.instance_methods.collect{|m| m.to_s}
71
- candidates |= Hash.instance_methods.collect{|m| m.to_s}
72
- select_message(receiver, message, candidates)
73
-
74
- when /^(:[^:.]*)$/
75
- # Symbol
76
- if Symbol.respond_to?(:all_symbols)
77
- sym = $1
78
- candidates = Symbol.all_symbols.collect{|s| ":" + s.id2name}
79
- candidates.grep(/^#{sym}/)
80
- else
81
- []
82
- end
83
-
84
- when /^::([A-Z][^:\.\(]*)$/
85
- # Absolute Constant or class methods
86
- receiver = $1
87
- candidates = Object.constants.collect{|m| m.to_s}
88
- candidates.grep(/^#{receiver}/).collect{|e| "::" + e}
89
-
90
- when /^([A-Z].*)::([^:.]*)$/
91
- # Constant or class methods
92
- receiver = $1
93
- message = Regexp.quote($2)
94
- begin
95
- candidates = eval("#{receiver}.constants.collect{|m| m.to_s}", bind)
96
- candidates |= eval("#{receiver}.methods.collect{|m| m.to_s}", bind)
97
- rescue RescuableException
98
- candidates = []
99
- end
100
- candidates.grep(/^#{message}/).collect{|e| receiver + "::" + e}
101
-
102
- when /^(:[^:.]+)\.([^.]*)$/
103
- # Symbol
104
- receiver = $1
105
- message = Regexp.quote($2)
106
-
107
- candidates = Symbol.instance_methods.collect{|m| m.to_s}
108
- select_message(receiver, message, candidates)
46
+ begin
47
+ bind = target
48
+
49
+ case input
50
+ when /^(\/[^\/]*\/)\.([^.]*)$/
51
+ # Regexp
52
+ receiver = $1
53
+ message = Regexp.quote($2)
54
+
55
+ candidates = Regexp.instance_methods.collect{|m| m.to_s}
56
+ select_message(receiver, message, candidates)
57
+
58
+ when /^([^\]]*\])\.([^.]*)$/
59
+ # Array
60
+ receiver = $1
61
+ message = Regexp.quote($2)
62
+
63
+ candidates = Array.instance_methods.collect{|m| m.to_s}
64
+ select_message(receiver, message, candidates)
65
+
66
+ when /^([^\}]*\})\.([^.]*)$/
67
+ # Proc or Hash
68
+ receiver = $1
69
+ message = Regexp.quote($2)
70
+
71
+ candidates = Proc.instance_methods.collect{|m| m.to_s}
72
+ candidates |= Hash.instance_methods.collect{|m| m.to_s}
73
+ select_message(receiver, message, candidates)
74
+
75
+ when /^(:[^:.]*)$/
76
+ # Symbol
77
+ if Symbol.respond_to?(:all_symbols)
78
+ sym = Regexp.quote($1)
79
+ candidates = Symbol.all_symbols.collect{|s| ":" + s.id2name}
80
+
81
+ candidates.grep(/^#{sym}/)
82
+ else
83
+ []
84
+ end
109
85
 
110
- when /^(-?(0[dbo])?[0-9_]+(\.[0-9_]+)?([eE]-?[0-9]+)?)\.([^.]*)$/
111
- # Numeric
112
- receiver = $1
113
- message = Regexp.quote($5)
86
+ when /^::([A-Z][^:\.\(]*)$/
87
+ # Absolute Constant or class methods
88
+ receiver = $1
89
+ candidates = Object.constants.collect{|m| m.to_s}
90
+ candidates.grep(/^#{receiver}/).collect{|e| "::" + e}
114
91
 
115
- begin
116
- candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
117
- rescue RescuableException
118
- candidates = []
119
- end
120
- select_message(receiver, message, candidates)
92
+ when /^([A-Z].*)::([^:.]*)$/
93
+ # Constant or class methods
94
+ receiver = $1
95
+ message = Regexp.quote($2)
96
+ begin
97
+ candidates = eval("#{receiver}.constants.collect{|m| m.to_s}", bind)
98
+ candidates |= eval("#{receiver}.methods.collect{|m| m.to_s}", bind)
99
+ rescue RescuableException
100
+ candidates = []
101
+ end
102
+ candidates.grep(/^#{message}/).collect{|e| receiver + "::" + e}
121
103
 
122
- when /^(-?0x[0-9a-fA-F_]+)\.([^.]*)$/
123
- # Numeric(0xFFFF)
124
- receiver = $1
125
- message = Regexp.quote($2)
104
+ when /^(:[^:.]+)\.([^.]*)$/
105
+ # Symbol
106
+ receiver = $1
107
+ message = Regexp.quote($2)
126
108
 
127
- begin
128
- candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
129
- rescue RescuableException
130
- candidates = []
131
- end
132
- select_message(receiver, message, candidates)
109
+ candidates = Symbol.instance_methods.collect{|m| m.to_s}
110
+ select_message(receiver, message, candidates)
133
111
 
134
- when /^(\$[^.]*)$/
135
- regmessage = Regexp.new(Regexp.quote($1))
136
- candidates = global_variables.collect{|m| m.to_s}.grep(regmessage)
112
+ when /^(-?(0[dbo])?[0-9_]+(\.[0-9_]+)?([eE]-?[0-9]+)?)\.([^.]*)$/
113
+ # Numeric
114
+ receiver = $1
115
+ message = Regexp.quote($5)
137
116
 
138
- when /^([^."].*)\.([^.]*)$/
139
- # variable
140
- receiver = $1
141
- message = Regexp.quote($2)
117
+ begin
118
+ candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
119
+ rescue RescuableException
120
+ candidates = []
121
+ end
122
+ select_message(receiver, message, candidates)
142
123
 
143
- gv = eval("global_variables", bind).collect{|m| m.to_s}
144
- lv = eval("local_variables", bind).collect{|m| m.to_s}
145
- cv = eval("self.class.constants", bind).collect{|m| m.to_s}
124
+ when /^(-?0x[0-9a-fA-F_]+)\.([^.]*)$/
125
+ # Numeric(0xFFFF)
126
+ receiver = $1
127
+ message = Regexp.quote($2)
146
128
 
147
- if (gv | lv | cv).include?(receiver) or /^[A-Z]/ =~ receiver && /\./ !~ receiver
148
- # foo.func and foo is local var. OR
149
- # Foo::Bar.func
150
129
  begin
151
- candidates = eval("#{receiver}.methods", bind).collect{|m| m.to_s}
130
+ candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
152
131
  rescue RescuableException
153
132
  candidates = []
154
133
  end
155
- else
156
- # func1.func2
157
- candidates = []
158
- ObjectSpace.each_object(Module){|m|
134
+ select_message(receiver, message, candidates)
135
+
136
+ when /^(\$[^.]*)$/
137
+ regmessage = Regexp.new(Regexp.quote($1))
138
+ candidates = global_variables.collect{|m| m.to_s}.grep(regmessage)
139
+
140
+ when /^([^."].*)\.([^.]*)$/
141
+ # variable
142
+ receiver = $1
143
+ message = Regexp.quote($2)
144
+
145
+ gv = eval("global_variables", bind).collect{|m| m.to_s}
146
+ lv = eval("local_variables", bind).collect{|m| m.to_s}
147
+ cv = eval("self.class.constants", bind).collect{|m| m.to_s}
148
+
149
+ if (gv | lv | cv).include?(receiver) or /^[A-Z]/ =~ receiver && /\./ !~ receiver
150
+ # foo.func and foo is local var. OR
151
+ # Foo::Bar.func
159
152
  begin
160
- name = m.name.to_s
153
+ candidates = eval("#{receiver}.methods", bind).collect{|m| m.to_s}
161
154
  rescue RescuableException
162
- name = ""
155
+ candidates = []
163
156
  end
164
- next if name != "IRB::Context" and
165
- /^(IRB|SLex|RubyLex|RubyToken)/ =~ name
166
- candidates.concat m.instance_methods(false).collect{|x| x.to_s}
167
- }
168
- candidates.sort!
169
- candidates.uniq!
170
- end
171
- select_message(receiver, message, candidates)
157
+ else
158
+ # func1.func2
159
+ candidates = []
160
+ ObjectSpace.each_object(Module){|m|
161
+ begin
162
+ name = m.name.to_s
163
+ rescue RescuableException
164
+ name = ""
165
+ end
166
+ next if name != "IRB::Context" and
167
+ /^(IRB|SLex|RubyLex|RubyToken)/ =~ name
168
+
169
+ # jruby doesn't always provide #instance_methods() on each
170
+ # object.
171
+ if m.respond_to?(:instance_methods)
172
+ candidates.concat m.instance_methods(false).collect{|x| x.to_s}
173
+ end
174
+ }
175
+ candidates.sort!
176
+ candidates.uniq!
177
+ end
178
+ select_message(receiver, message, candidates)
172
179
 
173
- when /^\.([^.]*)$/
174
- # unknown(maybe String)
180
+ when /^\.([^.]*)$/
181
+ # unknown(maybe String)
175
182
 
176
- receiver = ""
177
- message = Regexp.quote($1)
183
+ receiver = ""
184
+ message = Regexp.quote($1)
178
185
 
179
- candidates = String.instance_methods(true).collect{|m| m.to_s}
180
- select_message(receiver, message, candidates)
186
+ candidates = String.instance_methods(true).collect{|m| m.to_s}
187
+ select_message(receiver, message, candidates)
181
188
 
182
- else
183
- candidates = eval("methods | private_methods | local_variables | self.class.constants", bind).collect{|m| m.to_s}
189
+ else
190
+ candidates = eval(
191
+ "methods | private_methods | local_variables | " \
192
+ "self.class.constants | instance_variables",
193
+ bind
194
+ ).collect{|m| m.to_s}
195
+
196
+ if eval("respond_to?(:class_variables)", bind)
197
+ candidates += eval("class_variables", bind).collect { |m| m.to_s }
198
+ end
184
199
 
185
- (candidates|ReservedWords|commands).grep(/^#{Regexp.quote(input)}/)
200
+ (candidates|ReservedWords|commands).grep(/^#{Regexp.quote(input)}/)
201
+ end
202
+ rescue RescuableException
203
+ []
186
204
  end
187
205
  end
188
206
  end