Class: Zashoku::Item
- Inherits:
-
Object
- Object
- Zashoku::Item
- Defined in:
- lib/core/item.rb
Instance Attribute Summary collapse
-
#attr ⇒ Object
Returns the value of attribute attr.
Instance Method Summary collapse
-
#initialize(attributes) ⇒ Item
constructor
A new instance of Item.
- #method_missing(m, *args, &block) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Item
Returns a new instance of Item.
6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/core/item.rb', line 6 def initialize(attributes) @attributes = attributes keys = [] @attr = attributes.map { |k, v| pk = k.to_s.chars.map { |c| [c, c.swapcase] }.flatten kc = 0 kc += 1 while kc < pk.length && keys.include?(pk[kc]) keys << pk[kc] [pk[kc], v] }.to_h end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
18 19 20 21 22 |
# File 'lib/core/item.rb', line 18 def method_missing(m, *args, &block) return @attributes[m.to_s] if @attributes.key?(m.to_s) #raise "error #{m} not found" super end |
Instance Attribute Details
#attr ⇒ Object
Returns the value of attribute attr.
5 6 7 |
# File 'lib/core/item.rb', line 5 def attr @attr end |