I have a hash that looks something like this:

params = { :irrelevant => "A String",
           :choice1 => "Oh look, another one",
           :choice2 => "Even more strings",
           :choice3 => "But wait",
           :irrelevant2 => "The last string" }

And I want a simple way to reject all the keys that aren’t choice+int. It could be choice1, or choice1 through choice10. It varies.

How do I single out the keys with just the word choice and a digit or digits after them?

Bonus:

Turn the hash into a string with tab (\t) as a delimiter. I did this, but it took several lines of code. Usually master Rubicians can do it in one or so lines.

14 Answers
14

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *