Class: QuacksLike::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/quacks_like.rb

Instance Method Summary collapse

Constructor Details

#initialize(*methods) ⇒ Matcher

Returns a new instance of Matcher.



77
78
79
80
81
82
83
# File 'lib/quacks_like.rb', line 77

def initialize(*methods)
  @methods = methods.map do |m|
    sym = m.to_sym
    raise ArgumentError.new("#{m} could not be converted to a symbol") unless sym
    sym
  end
end

Instance Method Details

#===(object) ⇒ Object

Returns true iff object responds to all of self‘s methods.



86
87
88
# File 'lib/quacks_like.rb', line 86

def ===(object)
  @methods.all? { |m| object.respond_to?(m) }
end