Class: Contracts::Builtin::Eq

Inherits:
CallableClass show all
Defined in:
lib/contracts/builtin_contracts.rb

Overview

Takes a value v. If the argument is .equal to v, the contract passes, otherwise the contract fails. Example: Eq[Class]

Instance Method Summary collapse

Methods inherited from CallableClass

[]

Constructor Details

#initialize(value) ⇒ Eq

Returns a new instance of Eq.



252
253
254
255
# File 'lib/contracts/builtin_contracts.rb', line 252

def initialize(value)
  super()
  @value = value
end

Instance Method Details

#to_sObject



261
262
263
# File 'lib/contracts/builtin_contracts.rb', line 261

def to_s
  "to be equal to #{@value.inspect}"
end

#valid?(val) ⇒ Boolean

Returns:

  • (Boolean)


257
258
259
# File 'lib/contracts/builtin_contracts.rb', line 257

def valid?(val)
  @value.equal?(val)
end