Module: Crystalline::Enum
- Defined in:
- lib/crystalline/types.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
- #initialize(val) ⇒ Object
- #inspect ⇒ Object
- #known? ⇒ Boolean
- #serialize ⇒ Object
- #to_s ⇒ Object
Class Method Details
.included(base) ⇒ Object
96 97 98 |
# File 'lib/crystalline/types.rb', line 96 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#==(other) ⇒ Object
157 158 159 160 |
# File 'lib/crystalline/types.rb', line 157 def ==(other) other = other.serialize if other.is_a?(self.class) @val == other end |
#eql?(other) ⇒ Boolean
162 163 164 |
# File 'lib/crystalline/types.rb', line 162 def eql?(other) self == other end |
#hash ⇒ Object
166 167 168 |
# File 'lib/crystalline/types.rb', line 166 def hash @val.hash end |
#initialize(val) ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/crystalline/types.rb', line 100 def initialize(val) if self.class.instance_methods(false).include?(:initialize) super(val) else @val = val end end |
#inspect ⇒ Object
149 150 151 |
# File 'lib/crystalline/types.rb', line 149 def inspect "#<#{self.class} #{serialize.inspect}>" end |
#known? ⇒ Boolean
153 154 155 |
# File 'lib/crystalline/types.rb', line 153 def known? self.class.instance_variable_get(:@mapping)&.value?(self) || false end |
#serialize ⇒ Object
141 142 143 |
# File 'lib/crystalline/types.rb', line 141 def serialize @val end |
#to_s ⇒ Object
145 146 147 |
# File 'lib/crystalline/types.rb', line 145 def to_s serialize.to_s end |