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.



238
239
240
241
# File 'lib/contracts/builtin_contracts.rb', line 238

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

Instance Method Details

#valid?(val) ⇒ Boolean

Returns:

  • (Boolean)


243
244
245
# File 'lib/contracts/builtin_contracts.rb', line 243

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