Absolutely... an Array is perfect for ordered information.
actions = [
{ /abcd/ => lambda { do_this } },
{ /xyz/ => lambda { do_that } },
{ /abc/ => lambda { other } }
]
Then, all you do is...
actions.select { |action| action[input] }
where input = /xyz/ you will receive the appropriate hash (key and
Proc) in an array. So, to do something with that, you could...
actions.select { |action| action[input] }.first[input].call
which calls the Proc associated with the matching element.
I'm not too thrilled with its convolutedness, and I'm sure there's a
better way, but I'm pretty sleepy, so this is the best I'm coming up
with right now. :) As always, you can write a method to hide the gory
details.
def exec_route input
actions.select { |action| action[input] }.first[input].call
end
and just call:
exec_route /xyz/
and blam! do_that is executed!
Hope this helps.
M.T.