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.
177 178 179 180 |
# File 'lib/contracts/builtin_contracts.rb', line 177 def initialize(*meths) super() @meths = meths end |
Instance Method Details
#to_s ⇒ Object
188 189 190 |
# File 'lib/contracts/builtin_contracts.rb', line 188 def to_s "a value that responds to #{@meths.inspect}" end |
#valid?(val) ⇒ Boolean
182 183 184 185 186 |
# File 'lib/contracts/builtin_contracts.rb', line 182 def valid?(val) @meths.all? do |meth| val.respond_to? meth end end |