Permalink
Browse files

Pry::WrappedModule: add candidates Enumerator

This enables things like this: Pry::WrappedModule(mod).candidates.find(&:source)
returns the first candidate (monkeypatch) with accessible source code.
  • Loading branch information...
1 parent 2e40eb2 commit 90f95688cae15dd23a88f46c20d6c2dc05ab8e0c @banister banister committed Jan 28, 2013
Showing with 9 additions and 1 deletion.
  1. +9 −1 lib/pry/wrapped_module.rb
View
10 lib/pry/wrapped_module.rb
@@ -229,13 +229,21 @@ def candidate(rank)
@memoized_candidates[rank] ||= Candidate.new(self, rank)
end
-
# @return [Fixnum] The number of candidate definitions for the
# current module.
def number_of_candidates
method_candidates.count
end
+ # @return [Enumerator]
+ def candidates
+ Enumerator.new do |y|
+ (0...number_of_candidates).each do |num|
+ y << candidate(num)
+ end
+ 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 90f9568

Please sign in to comment.