class Contracts::Builtin::RespondTo

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]

Public Class Methods

new(*meths) click to toggle source
# File lib/contracts/builtin_contracts.rb, line 166
def initialize(*meths)
  @meths = meths
end

Public Instance Methods

to_s() click to toggle source
# File lib/contracts/builtin_contracts.rb, line 176
def to_s
  "a value that responds to #{@meths.inspect}"
end
valid?(val) click to toggle source
# File lib/contracts/builtin_contracts.rb, line 170
def valid?(val)
  @meths.all? do |meth|
    val.respond_to? meth
  end
end