class Array
def to_h
h = {}
each do |x|
arr = yield x
h[arr.first] = arr.last
end
h
end
end
str="foo=bar\nbaz=quux\napple=orange\n"
p str.split(/\n/).to_h { |pair| pair.split(/=/) }
|
Pastie
Support Pastie
or read my
Pastie << self
blog
class Array
def to_h
h = {}
each do |x|
arr = yield x
h[arr.first] = arr.last
end
h
end
end
str="foo=bar\nbaz=quux\napple=orange\n"
p str.split(/\n/).to_h { |pair| pair.split(/=/) }
|