Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Pry::WrappedModule: Make #candidates 1.8 friendly.

1.8 doesn't support Enumerator, so we return Generator instead.
  • Loading branch information...
commit 666ea4aa4c1fe86851689bafcdf25198683f7c9b 1 parent 2b8468a
@banister banister authored
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))
Please sign in to comment.
Something went wrong with that request. Please try again.