Sha256: c138f09bacdf22e0c15d33834fcadfcc3eb226be4c0b89ac1191fd4419a42b6c
Contents?: true
Size: 912 Bytes
Versions: 2
Compression:
Stored size: 912 Bytes
Contents
module ROXML module CoreExtensions module Array #:nodoc: module Conversions # Translates an array into a hash, where each element of the array is # an array with 2 elements: # # >> [[:key, :value], [1, 2], ['key', 'value']].to_h # => {:key => :value, 1 => 2, 'key' => 'value'} # def to_hash hash = inject({}) do |result, (k, v)| result[k] ||= [] result[k] << v result end hash.each_pair do |k, v| hash[k] = v.only if v.one? end hash end def to_h #:nodoc: to_hash end deprecate :to_h => :to_hash def apply_to(val) # Only makes sense for arrays of blocks... maybe better outside Array... inject(val) {|val, block| block.call(val) } end end end end end
Version data entries
2 entries across 2 versions & 2 rubygems
Version | Path |
---|---|
Empact-roxml-2.4.0 | lib/roxml/extensions/array/conversions.rb |
roxml-2.4.0 | lib/roxml/extensions/array/conversions.rb |