Class: Contracts::Send
- Inherits:
-
CallableClass
- Object
- CallableClass
- Contracts::Send
- Defined in:
- 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.
229 230 231 |
# File 'lib/contracts/builtin_contracts.rb', line 229 def initialize(*meths) @meths = meths end |
Instance Method Details
#to_s ⇒ Object
239 240 241 |
# File 'lib/contracts/builtin_contracts.rb', line 239 def to_s "a value that returns true for all of #{@meths.inspect}" end |
#valid?(val) ⇒ Boolean
233 234 235 236 237 |
# File 'lib/contracts/builtin_contracts.rb', line 233 def valid?(val) @meths.all? do |meth| val.send(meth) end end |