This is my first time using Ruby, and I need to use the inject method to create a hash from a given array. This code pretty closely mirrors several tutorials I've found, but get an undefined method `[]=' for nil:NilClass error when executing. Am I missing anything here?
def int_hash()
[[:key1, "value1"], [:key2, "value2"]].inject({}) do |hash, element|
hash[element.first] = element.last
puts hash
end
end
int_hash()
...do |hash, (k, v)| hash[k] = v...This makes use of array decomposition, which is a powerful and useful language feature.