Class: Contracts::Builtin::Enum
- Inherits:
-
CallableClass
- Object
- CallableClass
- Contracts::Builtin::Enum
- Defined in:
- lib/contracts-ruby2/lib/contracts/builtin_contracts.rb,
lib/contracts-ruby3/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
-
#initialize(*vals) ⇒ Enum
constructor
A new instance of Enum.
- #valid?(val) ⇒ Boolean
Methods inherited from CallableClass
Constructor Details
#initialize(*vals) ⇒ Enum
Returns a new instance of Enum.
224 225 226 |
# File 'lib/contracts-ruby2/lib/contracts/builtin_contracts.rb', line 224 def initialize(*vals) @vals = vals end |
Instance Method Details
#valid?(val) ⇒ Boolean
228 229 230 |
# File 'lib/contracts-ruby2/lib/contracts/builtin_contracts.rb', line 228 def valid?(val) @vals.include? val end |