Have an array of single pair hashes, like this:
arguments = [{:name=>"ABCD"},{:title=>"Awesome"},{:number=>4}]
I need to loop through and pull each one off as a key and value. Right now, I’m doing this:
def methodname(*arguments, &block)
arguments.each do |arg|
arg.each do |key, value|
# use my key and value
end
end
# use the &block here in awesome ways
end
Ick. Gotta be a better way, so I’m asking if someone knows it. I’ve searched and can’t seem to find this particular question on StackOverflow, but let me know if it’s out there.
EDIT: Added context to the code example.
If arguments are expected to be unique…
FWIW – if you can change this data structure, it might be a good idea to do so. This data is better represented in a single hash.
You can also define your method differently and avoid the problem altogether.