I have this code snippet, a bucket in this case is just an array within a larger array:
def Dict.get_slot(aDict, key, default=nil)
# Returns the index, key, and value of a slot found in a bucket.
bucket = Dict.get_bucket(aDict, key)
bucket.each_with_index do |kv, i|
k, v = kv
if key == k
return i, k, v
end
end
return -1, key, default
end
The two variables called k and v are set to the contens of kv. But how can this work, when kv only contains one value at a time?
I wrote this into another file:
bucket = ['key', 'value']
key = 'key'
bucket.each_with_index do |kv, i|
k, v = kv
if key == k
puts k, v, i
end
end
And then the v variable was empty:
key
0
My question is, why does multiple assignment work in the first example, but not in the second?