1
0
Fork 0
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:
John Mair 2013-01-29 20:22:51 +01:00
parent 2b8468a3b6
commit 666ea4aa4c

View file

@ -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))