Created
February 14, 2013 19:42
-
-
Save IanWhitney/4955714 to your computer and use it in GitHub Desktop.
Using inject to take two arrays and use them to populate a hash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @required_keys = [:email_address,:subject] | |
| @optional_keys = [:email_from] | |
| @params = {:email_address=>"test@test.com", :subject=>"email subject", :email_from=>"hi@test.com", :extra=>"not used"} | |
| all_params = (@required_keys + @optional_keys).inject({}) do |result, element| | |
| result[element] = @params[element] | |
| result | |
| end | |
| => {:email_address=>"test@test.com", :subject=>"email subject", :email_from=>"hi@test.com"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment