Convert an array to a hash

Posted by root Sun, 04 May 2008 21:56:00 GMT

class Array
  def to_h
    arr = self.dup
    if arr.size % 2 == 0
        Hash[*arr]
    else
        Hash[*arr << nil]
    end
  end
end

Posted in  | Tags  | no comments

Comments

Comments are disabled