Class: Contracts::Builtin::Send

Inherits:
CallableClass show all
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

Methods inherited from CallableClass

[]

Constructor Details

#initialize(*meths) ⇒ Send

Returns a new instance of Send.


199
200
201
202
# File 'lib/contracts/builtin_contracts.rb', line 199

def initialize(*meths)
  super()
  @meths = meths
end

Instance Method Details

#to_sObject


210
211
212
# File 'lib/contracts/builtin_contracts.rb', line 210

def to_s
  "a value that returns true for all of #{@meths.inspect}"
end

#valid?(val) ⇒ Boolean

Returns:

  • (Boolean)

204
205
206
207
208
# File 'lib/contracts/builtin_contracts.rb', line 204

def valid?(val)
  @meths.all? do |meth|
    val.send(meth)
  end
end