Module: Crystalline::Enum

Defined in:
lib/crystalline/types.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



98
99
100
# File 'lib/crystalline/types.rb', line 98

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#==(other) ⇒ Object



159
160
161
162
# File 'lib/crystalline/types.rb', line 159

def ==(other)
  other = other.serialize if other.is_a?(self.class)
  @val == other
end

#eql?(other) ⇒ Boolean

Returns:



164
165
166
# File 'lib/crystalline/types.rb', line 164

def eql?(other)
  self == other
end

#hashObject



168
169
170
# File 'lib/crystalline/types.rb', line 168

def hash
  @val.hash
end

#initialize(val) ⇒ Object



102
103
104
105
106
107
108
# File 'lib/crystalline/types.rb', line 102

def initialize(val)
  if self.class.instance_methods(false).include?(:initialize)
    super(val)
  else
    @val = val
  end
end

#inspectObject



151
152
153
# File 'lib/crystalline/types.rb', line 151

def inspect
  "#<#{self.class} #{serialize.inspect}>"
end

#known?Boolean

Returns:



155
156
157
# File 'lib/crystalline/types.rb', line 155

def known?
  self.class.instance_variable_get(:@mapping)&.value?(self) || false
end

#serializeObject



143
144
145
# File 'lib/crystalline/types.rb', line 143

def serialize
  @val
end

#to_sObject



147
148
149
# File 'lib/crystalline/types.rb', line 147

def to_s
  serialize.to_s
end