I am writing a small helper to walk a hash or an array of arrays to
find a nested key. (by the way, if there is an existing function for
this in Ruby I will willingly take it instead).
The call is this
the def is this
key = key.to_s
collection.each do |check|
return check if check == key
keywalk(check,key) if (check.is_a?(Array) or check.is_a?(Hash))
The problem that I have is that key is always nil inside
collection.each even though it is define inside the method and a puts
shows that it has the value passed as that parameter. Why is key
evidently out of scope inside the iterator?