Class: RR::Expectations::WildcardMatchers::DuckType

Inherits:
Object
  • Object
show all
Defined in:
lib/rr/expectations/wildcard_matchers/duck_type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*required_methods) ⇒ DuckType

Returns a new instance of DuckType.



7
8
9
# File 'lib/rr/expectations/wildcard_matchers/duck_type.rb', line 7

def initialize(*required_methods)
  @required_methods = required_methods
end

Instance Attribute Details

#required_methodsObject

Returns the value of attribute required_methods.



5
6
7
# File 'lib/rr/expectations/wildcard_matchers/duck_type.rb', line 5

def required_methods
  @required_methods
end

Instance Method Details

#==(other) ⇒ Object



19
20
21
22
# File 'lib/rr/expectations/wildcard_matchers/duck_type.rb', line 19

def ==(other)
  return false unless other.is_a?(self.class)
  self.required_methods == other.required_methods
end

#wildcard_match?(other) ⇒ Boolean

Returns:



11
12
13
14
15
16
17
# File 'lib/rr/expectations/wildcard_matchers/duck_type.rb', line 11

def wildcard_match?(other)
  return true if self == other
  required_methods.each do |m|
    return false unless other.respond_to?(m)
  end
  return true
end