Module: Crystalline::Enum

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



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

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

Instance Method Details

#==(other) ⇒ Object



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

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

#eql?(other) ⇒ Boolean

Returns:



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

def eql?(other)
  self == other
end

#hashObject



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

def hash
  @val.hash
end

#initialize(val) ⇒ Object



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

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

#inspectObject



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

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

#known?Boolean

Returns:



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

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

#serializeObject



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

def serialize
  @val
end

#to_sObject



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

def to_s
  serialize.to_s
end