Class: Loady::AttributeArray
- Inherits:
-
Array
- Object
- Array
- Loady::AttributeArray
- Defined in:
- lib/loady/attribute_array.rb
Instance Method Summary collapse
-
#to_attributes(names, options = {}) ⇒ Object
usage: aa = Loady::AttributeArray.new([‘john’, ‘doe’]) aa.to_attributes([:first, :last]) => { first: ‘john’, last: ‘doe’ }.
Instance Method Details
#to_attributes(names, options = {}) ⇒ Object
usage: aa = Loady::AttributeArray.new([‘john’, ‘doe’]) aa.to_attributes([:first, :last])
> { first: ‘john’, last: ‘doe’ }
options:
strip: false -- default = true
-- array values must be strings if :strip is true
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/loady/attribute_array.rb', line 12 def to_attributes(names, = {}) = { strip: true }.merge() attr_hash = {} names.each_with_index do |name, i| attr_hash[name] = if i < size && self[i] [:strip] ? self[i].to_s.strip : self[i] end end attr_hash end |