Sha256: 4517de5725fbc592b7a863a2eeb34002d565646680ebac4e592b62c9507f7ffa
Contents?: true
Size: 578 Bytes
Versions: 2
Compression:
Stored size: 578 Bytes
Contents
class Presenting::FieldSet < Array def initialize(field_class, primary, secondary) @klass = field_class @primary_attribute = primary @secondary_attribute = secondary end def <<(field) if field.is_a? Hash k, v = *field.to_a.first opts = v.is_a?(Hash) ? v : {@secondary_attribute => v} opts[@primary_attribute] = k else opts = {@primary_attribute => field} end super @klass.new(opts) end def [](key) detect{|i| i.send(@primary_attribute) == key} end def []=(key, val) self << {key => val} end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
presenting-2.0.0 | lib/presenting/field_set.rb |
presenting-1.0.0 | lib/presenting/field_set.rb |