Class: MethodLister::FindResult
- Inherits:
-
Object
- Object
- MethodLister::FindResult
- Defined in:
- lib/method_lister/find_result.rb
Constant Summary collapse
- VISIBILITIES =
[:public, :protected, :private]
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #has_methods?(visibility = :all) ⇒ Boolean
-
#initialize(object, options = {}) ⇒ FindResult
constructor
A new instance of FindResult.
- #inspect ⇒ Object
- #methods(visibility) ⇒ Object
- #narrow_to_methods_matching!(rx) ⇒ Object
Constructor Details
#initialize(object, options = {}) ⇒ FindResult
Returns a new instance of FindResult.
6 7 8 9 10 11 12 |
# File 'lib/method_lister/find_result.rb', line 6 def initialize(object, ={}) @object = object @methods = Hash.new VISIBILITIES.each do |visibility| @methods[visibility] = [visibility] || Array.new end end |
Instance Attribute Details
#object ⇒ Object (readonly)
Returns the value of attribute object.
3 4 5 |
# File 'lib/method_lister/find_result.rb', line 3 def object @object end |
Instance Method Details
#==(other) ⇒ Object
37 38 39 40 |
# File 'lib/method_lister/find_result.rb', line 37 def ==(other) object.eql?(other.object) && methods(:all).sort == other.methods(:all).sort end |
#has_methods?(visibility = :all) ⇒ Boolean
24 25 26 |
# File 'lib/method_lister/find_result.rb', line 24 def has_methods?(visibility=:all) !methods(visibility).empty? end |
#inspect ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/method_lister/find_result.rb', line 42 def inspect repr = "object=#{object.inspect}\n" VISIBILITIES.each do |visibility| repr += "#{visibility}=#{methods(visibility).sort.inspect}\n" end repr end |
#methods(visibility) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/method_lister/find_result.rb', line 14 def methods(visibility) if visibility == :all VISIBILITIES.inject(Array.new) { |result, viz| result + methods(viz) } elsif VISIBILITIES.include? visibility @methods[visibility] else raise ArgumentError, "Unknown visibility #{visibility.inspect}" end.sort end |
#narrow_to_methods_matching!(rx) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/method_lister/find_result.rb', line 28 def narrow_to_methods_matching!(rx) VISIBILITIES.each do |visibility| @methods[visibility] = @methods[visibility].select do |method| method =~ rx || method == "method_missing" end end self end |