From 666ea4aa4c1fe86851689bafcdf25198683f7c9b Mon Sep 17 00:00:00 2001 From: John Mair Date: Tue, 29 Jan 2013 20:22:51 +0100 Subject: [PATCH] Pry::WrappedModule: Make #candidates 1.8 friendly. 1.8 doesn't support Enumerator, so we return Generator instead. --- lib/pry/wrapped_module.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/pry/wrapped_module.rb b/lib/pry/wrapped_module.rb index ca084d2b..8ecfb9bf 100644 --- a/lib/pry/wrapped_module.rb +++ b/lib/pry/wrapped_module.rb @@ -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))