mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Pry::WrappedModule: Make #candidates 1.8 friendly.
1.8 doesn't support Enumerator, so we return Generator instead.
This commit is contained in:
parent
2b8468a3b6
commit
666ea4aa4c
1 changed files with 14 additions and 2 deletions
|
@ -237,13 +237,25 @@ class Pry
|
|||
|
||||
# @return [Enumerator]
|
||||
def candidates
|
||||
Enumerator.new do |y|
|
||||
generator.new do |y|
|
||||
(0...number_of_candidates).each do |num|
|
||||
y << candidate(num)
|
||||
y.yield candidate(num)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Ruby 1.8 doesn't support `Enumerator` (it's called Generator instead)
|
||||
#
|
||||
# @return [Object] Return the appropriate generator class.
|
||||
def generator
|
||||
@generator ||= if defined?(Enumerator)
|
||||
Enumerator
|
||||
else
|
||||
require 'generator'
|
||||
Generator
|
||||
end
|
||||
end
|
||||
|
||||
# @return [Boolean] Whether YARD docs are available for this module.
|
||||
def yard_docs?
|
||||
!!(defined?(YARD) && YARD::Registry.at(name))
|
||||
|
|
Loading…
Reference in a new issue