Class: MetaEnum::Value
- Inherits:
-
Object
- Object
- MetaEnum::Value
- Defined in:
- lib/meta_enum/value.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(number, name, data, type) ⇒ Value
constructor
A new instance of Value.
- #inspect ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(number, name, data, type) ⇒ Value
Returns a new instance of Value.
5 6 7 8 9 10 11 |
# File 'lib/meta_enum/value.rb', line 5 def initialize(number, name, data, type) @number = Integer(number) @name = name.to_sym @data = data @type = type freeze end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/meta_enum/value.rb', line 3 def data @data end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/meta_enum/value.rb', line 3 def name @name end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
3 4 5 |
# File 'lib/meta_enum/value.rb', line 3 def number @number end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
3 4 5 |
# File 'lib/meta_enum/value.rb', line 3 def type @type end |
Instance Method Details
#==(other) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/meta_enum/value.rb', line 13 def ==(other) equal?(other) || equal?(type[other]) # type[] will raise for certain bad keys. Those are obviously not equal so return false. rescue ArgumentError, KeyError false end |
#inspect ⇒ Object
24 25 26 |
# File 'lib/meta_enum/value.rb', line 24 def inspect "#<#{self.class}: #{name}: #{number}, data: #{data.inspect}>" end |
#to_i ⇒ Object
21 |
# File 'lib/meta_enum/value.rb', line 21 def to_i; number; end |
#to_s ⇒ Object
22 |
# File 'lib/meta_enum/value.rb', line 22 def to_s; name.to_s; end |