Method: Enumerable::Hashifier#flat

Defined in:
lib/core/facets/enumerable/hashify.rb

#flatObject

This is equivalent to Hash, but it will pad the array with a nil object if there are not an even number of elements.

a = [:a,1,[:b,2,:c]]
a.to_h_flat  #=> { :a=>1, :b=>2, :c=>nil }


79
80
81
82
83
# File 'lib/core/facets/enumerable/hashify.rb', line 79

def flat
  a = @enum.to_a.flatten
  a << nil if a.size.odd?
  Hash[*a]
end