What's happening here is it's breaking out the key/value pair variable kv into two separate variables k and v. You'll need to adjust your code to look like this:
arr = [["cow", "moo"], ["duck", "quack"]]
arr.each_with_index do |kv, i|
k, v = kv
puts k
puts v
end
What's happening here is demonstrated by this:
kv = [ :key, :value ]
# Assign k to the first value, v to the second in kv
k, v = kv
k
# => :key
v
# => :value
A less messy way of doing this break-out is this:
arr.each_with_index do |(k, v), i|
# ... Use k and v normally
end
That notation allows you to expand the array into separate variables in advance of using them. It's a trick that comes in handy when dealing with value pairs of this sort.
It's worth noting you wouldn't have to do this if you didn't use each_with_index, as each is sufficient here since that index value is never used:
each do |k, v|
# ...
end
k = kvandv = kv.arr.each_with_index ....get_in the method name.