Class: Contracts::Constraints::RespondTo

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

Direct Known Subclasses

DuckType

Instance Method Summary collapse

Methods inherited from Base

#to_h

Constructor Details

#initialize(*methods) ⇒ RespondTo

Returns a new instance of RespondTo.



268
# File 'lib/contracts.rb', line 268

def initialize(*methods) = @methods = methods

Instance Method Details

#descriptionObject



270
# File 'lib/contracts.rb', line 270

def description = "responding to #{@methods.join(', ')}"

#matches?(value) ⇒ Boolean

Returns:

  • (Boolean)


269
# File 'lib/contracts.rb', line 269

def matches?(value) = @methods.all? { |method| value.respond_to?(method) }