Skip to content

Instantly share code, notes, and snippets.

@daveworth
Created November 9, 2011 18:46
Show Gist options
  • Select an option

  • Save daveworth/1352484 to your computer and use it in GitHub Desktop.

Select an option

Save daveworth/1352484 to your computer and use it in GitHub Desktop.
[["websites", /website/i], ["emails", /email/i], ["phones", /phone|fax|cell/i]].each do |getter_data|
data_type, regex = *getter_data
@wallace
Copy link

wallace commented Nov 9, 2011

 [["websites", /website/i], ["emails", /email/i], ["phones", /phone|fax|cell/i]].each do |(data_type,regex)|
      ....

@daveworth
Copy link
Author

SWEET!

@alindeman
Copy link

Also something to file away .. that kind of Array structure can be easily made into a Hash with Hash.[]

ruby-1.9.2-p290 :001 > Hash[[["websites", /website/i], ["emails", /email/i], ["phones", /phone|fax|cell/i]]]
 => {"websites"=>/website/i, "emails"=>/email/i, "phones"=>/phone|fax|cell/i} 

@daveworth
Copy link
Author

AL: thanks! I knew the latter and I suppose it's almost identical to what I need to accomplish above. After converting to a hash then I can do #each and the block variables are the keys/values resp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment