Class: Contracts::Builtin::RespondTo
- Inherits:
-
CallableClass
- Object
- CallableClass
- Contracts::Builtin::RespondTo
- Defined in:
- lib/contracts/builtin_contracts.rb
Overview
Takes a variable number of method names as symbols. The contract passes if the argument responds to all of those methods. Example: RespondTo[:password, :credit_card]
Instance Method Summary collapse
-
#initialize(*meths) ⇒ RespondTo
constructor
A new instance of RespondTo.
- #to_s ⇒ Object
- #valid?(val) ⇒ Boolean
Methods inherited from CallableClass
Constructor Details
#initialize(*meths) ⇒ RespondTo
Returns a new instance of RespondTo.
165 166 167 |
# File 'lib/contracts/builtin_contracts.rb', line 165 def initialize(*meths) @meths = meths end |
Instance Method Details
#to_s ⇒ Object
175 176 177 |
# File 'lib/contracts/builtin_contracts.rb', line 175 def to_s "a value that responds to #{@meths.inspect}" end |
#valid?(val) ⇒ Boolean
169 170 171 172 173 |
# File 'lib/contracts/builtin_contracts.rb', line 169 def valid?(val) @meths.all? do |meth| val.respond_to? meth end end |