Class: Contracts::Builtin::Enum

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

Overview

Takes a list of values, e.g. [:a, :b, :c]. If argument is included in the list, the contract passes.

Example: Enum[:a, :b, :c]?

Instance Method Summary collapse

Methods inherited from CallableClass

[]

Constructor Details

#initialize(*vals) ⇒ Enum

Returns a new instance of Enum.



223
224
225
# File 'lib/contracts/builtin_contracts.rb', line 223

def initialize(*vals)
  @vals = vals
end

Instance Method Details

#valid?(val) ⇒ Boolean

Returns:

  • (Boolean)


227
228
229
# File 'lib/contracts/builtin_contracts.rb', line 227

def valid?(val)
  @vals.include? val
end