Class: Item
- Inherits:
-
Object
- Object
- Item
- Defined in:
- lib/script_storage_item.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(key, value) ⇒ Item
constructor
A new instance of Item.
- #show ⇒ Object
Constructor Details
#initialize(key, value) ⇒ Item
Returns a new instance of Item.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/script_storage_item.rb', line 6 def initialize(key, value) case value.class.to_s.downcase when 'array' @value = [] value.each do |v| @value.append(v) end else @value = value end @key = key end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
4 5 6 |
# File 'lib/script_storage_item.rb', line 4 def key @key end |
#value ⇒ Object
Returns the value of attribute value.
4 5 6 |
# File 'lib/script_storage_item.rb', line 4 def value @value end |
Instance Method Details
#==(other) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/script_storage_item.rb', line 34 def ==(other) @key == if other.class == String other else other.key end end |
#show ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/script_storage_item.rb', line 21 def show type = @value.class.to_s.downcase case type when 'string' "#{key}: #{value}" when 'array' "#{key}(#{type}): #{@value.join(', ')}" else "#{key}(#{type}): #{value}" end end |