Permalink
Browse files

WrappedModule#candidates: return Array on JRuby >=1.9

JRuby 1.9 has a nasty bug with `Enumerator#find_index`, which we utilise
in the code of `whereami` command.

More information on the bug: jruby/jruby#525

Simply return an Array, formed from the original Enumerator on JRuby 1.9
and higher. This kills the efficiency, but leastwise, it will be
working.

As a bonus, remove some a junk method.
  • Loading branch information...
1 parent 9a29999 commit 684ac1fccf10604366c891cacea36be36d4135c1 @kyrylo kyrylo committed Feb 4, 2013
Showing with 12 additions and 10 deletions.
  1. +12 −10 lib/pry/wrapped_module.rb
View
@@ -235,13 +235,19 @@ def number_of_candidates
method_candidates.count
end
- # @return [Enumerator]
+ # @note On JRuby 1.9 and higher, in certain conditions, this method chucks
+ # away its ability to be quick (when there are lots of monkey patches,
+ # like in Rails). However, it should be efficient enough on other rubies.
+ # @see https://github.com/jruby/jruby/issues/525
+ # @return [Enumerator, Array] on JRuby 1.9 and higher returns Array, on
+ # other rubies returns Enumerator
def candidates
- generator.new do |y|
- (0...number_of_candidates).each do |num|
- y.yield candidate(num)
- end
- end
+ enum = generator.new do |y|
+ (0...number_of_candidates).each do |num|
+ y.yield candidate(num)
+ end
+ end
+ Pry::Helpers::BaseHelpers.jruby_19? ? enum.to_a : enum
end
# @return [Boolean] Whether YARD docs are available for this module.
@@ -267,10 +273,6 @@ def super(times=1)
Pry::WrappedModule(sup) if sup
end
- def first_module_candidate_with_source
-
- end
-
private
# Ruby 1.8 doesn't support `Enumerator` (it's called Generator instead)

0 comments on commit 684ac1f

Please sign in to comment.