Class: RR::WildcardMatchers::DuckType
- Inherits:
-
Object
- Object
- RR::WildcardMatchers::DuckType
- Defined in:
- lib/rr/wildcard_matchers/duck_type.rb
Instance Attribute Summary collapse
-
#required_methods ⇒ Object
Returns the value of attribute required_methods.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#initialize(*required_methods) ⇒ DuckType
constructor
A new instance of DuckType.
- #inspect ⇒ Object
- #wildcard_match?(other) ⇒ Boolean
Constructor Details
#initialize(*required_methods) ⇒ DuckType
Returns a new instance of DuckType.
6 7 8 |
# File 'lib/rr/wildcard_matchers/duck_type.rb', line 6 def initialize(*required_methods) @required_methods = required_methods end |
Instance Attribute Details
#required_methods ⇒ Object
Returns the value of attribute required_methods.
4 5 6 |
# File 'lib/rr/wildcard_matchers/duck_type.rb', line 4 def required_methods @required_methods end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
15 16 17 18 |
# File 'lib/rr/wildcard_matchers/duck_type.rb', line 15 def ==(other) other.is_a?(self.class) && other.required_methods == self.required_methods end |
#inspect ⇒ Object
21 22 23 24 25 |
# File 'lib/rr/wildcard_matchers/duck_type.rb', line 21 def inspect formatted_required_methods = required_methods.map { |method_name| method_name.inspect }.join(', ') "duck_type(#{formatted_required_methods})" end |
#wildcard_match?(other) ⇒ Boolean
10 11 12 13 |
# File 'lib/rr/wildcard_matchers/duck_type.rb', line 10 def wildcard_match?(other) self == other || required_methods.all? {|m| other.respond_to?(m) } end |