Skip to content

Commit

Permalink
Pry::WrappedModule: add candidates Enumerator
Browse files Browse the repository at this point in the history
This enables things like this: Pry::WrappedModule(mod).candidates.find(&:source)
returns the first candidate (monkeypatch) with accessible source code.
  • Loading branch information
banister committed Jan 29, 2013
1 parent 2e40eb2 commit 90f9568
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/pry/wrapped_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 90f9568

Please sign in to comment.