Class: QuacksLike::Matcher
- Inherits:
-
Object
- Object
- QuacksLike::Matcher
- Defined in:
- lib/quacks_like.rb
Instance Method Summary collapse
-
#===(object) ⇒ Object
Returns
true
iffobject
responds to all ofself
‘s methods. -
#initialize(*methods) ⇒ Matcher
constructor
A new instance of Matcher.
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 |