Class: Contracts::Builtin::Args

Inherits:
CallableClass show all
Defined in:
lib/contracts-ruby2/lib/contracts/builtin_contracts.rb,
lib/contracts-ruby3/lib/contracts/builtin_contracts.rb

Overview

Used for *args (variadic functions). Takes a contract and uses it to validate every element passed in through *args. Example: Args[Or[String, Num]]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from CallableClass

[]

Constructor Details

#initialize(contract) ⇒ Args

Returns a new instance of Args.



327
328
329
# File 'lib/contracts-ruby2/lib/contracts/builtin_contracts.rb', line 327

def initialize(contract)
  @contract = contract
end

Instance Attribute Details

#contractObject (readonly)

Returns the value of attribute contract.



326
327
328
# File 'lib/contracts-ruby2/lib/contracts/builtin_contracts.rb', line 326

def contract
  @contract
end

Instance Method Details

#to_sObject



331
332
333
# File 'lib/contracts-ruby2/lib/contracts/builtin_contracts.rb', line 331

def to_s
  "Args[#{@contract}]"
end