Class: Kali::Enum

Inherits:
Set
  • Object
show all
Defined in:
lib/kali/type.rb

Overview

Public: Helper class that allows us to easily restrict a value from a set of predetermined values. It’s just a Set that implements the case equality operator to check for Set inclusion.

This is meant to be used as a Type restriction. See Type for examples.

Examples:

Enum[1, 2, 3] === 1 #=> true
Enum[1, 2, 3] === 5 #=> false

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.[](*values) ⇒ Object



110
111
112
# File 'lib/kali/type.rb', line 110

def self.[](*values)
  new(values).freeze
end

Instance Method Details

#===(element) ⇒ Object



114
115
116
# File 'lib/kali/type.rb', line 114

def ===(element)
  include?(element)
end