module Enumerable

Public Instance Methods

to_h(*arg) click to toggle source
# File lib/taxjar/base.rb, line 8
def to_h(*arg)
  h = {}
  each_with_index(*arg) do |elem, i|
    unless elem.respond_to?(:to_ary)
      raise TypeError, "wrong element type #{elem.class} at #{i} (expected array)"
    end

    ary = elem.to_ary
    if ary.size != 2
      raise ArgumentError, "wrong array length at #{i} (expected 2, was #{ary.size})"
    end

    h[ary[0]] = ary[1]
  end
  h
end