class RR::WildcardMatchers::DuckType

Attributes

required_methods[RW]

Public Class Methods

new(*required_methods) click to toggle source
# File lib/rr/wildcard_matchers/duck_type.rb, line 6
def initialize(*required_methods)
  @required_methods = required_methods
end

Public Instance Methods

==(other) click to toggle source
# File lib/rr/wildcard_matchers/duck_type.rb, line 25
def ==(other)
  return false unless other.is_a?(self.class)
  self.required_methods == other.required_methods
end
Also aliased as: eql?
eql?(other)
Alias for: ==
inspect() click to toggle source
# File lib/rr/wildcard_matchers/duck_type.rb, line 18
def inspect
  formatted_required_methods = required_methods.collect do |method_name|
    method_name.inspect
  end.join(', ')
  "duck_type(#{formatted_required_methods})"
end
wildcard_match?(other) click to toggle source
# File lib/rr/wildcard_matchers/duck_type.rb, line 10
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