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
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
164 165 166 |
# File 'lib/crystalline/types.rb', line 164 def eql?(other) self == other end |
#hash ⇒ Object
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 |
#inspect ⇒ Object
151 152 153 |
# File 'lib/crystalline/types.rb', line 151 def inspect "#<#{self.class} #{serialize.inspect}>" end |
#known? ⇒ Boolean
155 156 157 |
# File 'lib/crystalline/types.rb', line 155 def known? self.class.instance_variable_get(:@mapping)&.value?(self) || false end |
#serialize ⇒ Object
143 144 145 |
# File 'lib/crystalline/types.rb', line 143 def serialize @val end |
#to_s ⇒ Object
147 148 149 |
# File 'lib/crystalline/types.rb', line 147 def to_s serialize.to_s end |