Permalink
Browse files

Pry::WrappedModule: Make #candidates 1.8 friendly.

1.8 doesn't support Enumerator, so we return Generator instead.
  • Loading branch information...
1 parent 2b8468a commit 666ea4aa4c1fe86851689bafcdf25198683f7c9b @banister banister committed Jan 29, 2013
Showing with 14 additions and 2 deletions.
  1. +14 −2 lib/pry/wrapped_module.rb
View
16 lib/pry/wrapped_module.rb
@@ -237,13 +237,25 @@ def number_of_candidates
# @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))

0 comments on commit 666ea4a

Please sign in to comment.