Class: Kind::Enum::Item
- Inherits:
-
Object
- Object
- Kind::Enum::Item
- Defined in:
- lib/kind/enum/item.rb
Constant Summary collapse
- Underscore =
->(arg) do str = String(arg).strip str.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2') str.gsub!(/([a-z\d])([A-Z])/, '\1_\2') str.tr!("-", "_") str.downcase! str end
Instance Attribute Summary collapse
-
#inspect ⇒ Object
readonly
Returns the value of attribute inspect.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#to_s ⇒ Object
(also: #key, #to_str)
readonly
Returns the value of attribute to_s.
-
#to_sym ⇒ Object
readonly
Returns the value of attribute to_sym.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #==(arg) ⇒ Object (also: #===)
-
#initialize(key, val) ⇒ Item
constructor
A new instance of Item.
- #to_ary ⇒ Object
Constructor Details
#initialize(key, val) ⇒ Item
Returns a new instance of Item.
20 21 22 23 24 25 26 27 |
# File 'lib/kind/enum/item.rb', line 20 def initialize(key, val) @value = val.frozen? ? val : val.dup.freeze @to_s = Kind.respond_to(key, :to_sym).to_s @name = Underscore[key].upcase.freeze @to_sym = key.to_sym @inspect = ('#<Kind::Enum::Item name=%p to_s=%p value=%p>' % [@name, @to_s, @value]).freeze end |
Instance Attribute Details
#inspect ⇒ Object (readonly)
Returns the value of attribute inspect.
15 16 17 |
# File 'lib/kind/enum/item.rb', line 15 def inspect @inspect end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/kind/enum/item.rb', line 15 def name @name end |
#to_s ⇒ Object (readonly) Also known as: key, to_str
Returns the value of attribute to_s.
15 16 17 |
# File 'lib/kind/enum/item.rb', line 15 def to_s @to_s end |
#to_sym ⇒ Object (readonly)
Returns the value of attribute to_sym.
15 16 17 |
# File 'lib/kind/enum/item.rb', line 15 def to_sym @to_sym end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
15 16 17 |
# File 'lib/kind/enum/item.rb', line 15 def value @value end |