{"action":"closed","issue":{"url":"https://api.github.com/repos/aws/aws-sdk-ruby/issues/647","labels_url":"https://api.github.com/repos/aws/aws-sdk-ruby/issues/647/labels{/name}","comments_url":"https://api.github.com/repos/aws/aws-sdk-ruby/issues/647/comments","events_url":"https://api.github.com/repos/aws/aws-sdk-ruby/issues/647/events","html_url":"https://github.com/aws/aws-sdk-ruby/issues/647","id":45955542,"number":647,"title":"Tip on hash merging","user":{"login":"baweaver","id":979723,"avatar_url":"https://avatars.githubusercontent.com/u/979723?v=3","gravatar_id":"","url":"https://api.github.com/users/baweaver","html_url":"https://github.com/baweaver","followers_url":"https://api.github.com/users/baweaver/followers","following_url":"https://api.github.com/users/baweaver/following{/other_user}","gists_url":"https://api.github.com/users/baweaver/gists{/gist_id}","starred_url":"https://api.github.com/users/baweaver/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/baweaver/subscriptions","organizations_url":"https://api.github.com/users/baweaver/orgs","repos_url":"https://api.github.com/users/baweaver/repos","events_url":"https://api.github.com/users/baweaver/events{/privacy}","received_events_url":"https://api.github.com/users/baweaver/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2014-10-16T07:16:07Z","updated_at":"2015-01-15T01:03:59Z","closed_at":"2015-01-15T01:03:59Z","body":"I've noticed this pattern a lot around the code:\r\n\r\n```ruby\r\n@ec2.key_pairs.inject({}) do |hash, key_pair|\r\n  hash[key_pair.name] = key_pair.fingerprint\r\n  hash\r\nend\r\n```\r\n\r\nIt could be written as:\r\n\r\n```ruby\r\n@ec2.key_pairs.reduce({}) { |hash, key_pair|\r\n  hash.merge! key_pair.name => key_pair.fingerprint\r\n}\r\n```\r\n\r\nMinor, yes, but it can save a few lines on occasion and relieve the need to explicitly put hash at the end as the implied return as ``merge`` returns the hash. I use ``merge!`` for a minor memory / speed gain, considering the accumulator (hash) is being returned that way either way."}}