Method: Array#to_h_splat

Defined in:
lib/core/facets/to_hash.rb

#to_h_splatObject

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_splat  #=> { :a=>1, :b=>2, :c=>nil }


120
121
122
123
124
# File 'lib/core/facets/to_hash.rb', line 120

def to_h_splat
  a = dup
  a << nil if a.size % 2 == 1
  Hash[*a]
end