Class: Contracts::Builtin::Send
- Inherits:
-
CallableClass
- Object
- CallableClass
- Contracts::Builtin::Send
- Defined in:
- lib/contracts-ruby2/lib/contracts/builtin_contracts.rb,
lib/contracts-ruby3/lib/contracts/builtin_contracts.rb
Overview
Takes a variable number of method names as symbols. Given an argument, all of those methods are called on the argument one by one. If they all return true, the contract passes. Example: Send[:valid?]
Instance Method Summary collapse
-
#initialize(*meths) ⇒ Send
constructor
A new instance of Send.
- #to_s ⇒ Object
- #valid?(val) ⇒ Boolean
Methods inherited from CallableClass
Constructor Details
#initialize(*meths) ⇒ Send
Returns a new instance of Send.
187 188 189 |
# File 'lib/contracts-ruby2/lib/contracts/builtin_contracts.rb', line 187 def initialize(*meths) @meths = meths end |
Instance Method Details
#to_s ⇒ Object
197 198 199 |
# File 'lib/contracts-ruby2/lib/contracts/builtin_contracts.rb', line 197 def to_s "a value that returns true for all of #{@meths.inspect}" end |
#valid?(val) ⇒ Boolean
191 192 193 194 195 |
# File 'lib/contracts-ruby2/lib/contracts/builtin_contracts.rb', line 191 def valid?(val) @meths.all? do |meth| val.send(meth) end end |