Last active
April 13, 2016 17:23
-
-
Save tribals/55c85c41d41caa266ab6a27aa5eb0421 to your computer and use it in GitHub Desktop.
This file contains 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
# assuming that `things` is an array of hashes which we want to process in some way | |
things = [ | |
{ one: 42, two: 'spam' }, | |
# ... and so on | |
{ one: 24, two: 'maps' } | |
] | |
things.map do |thing| | |
hsh = {} | |
hsh[:number] = thing[:one] * 2 + 3 # or whatewer | |
# more complex processing, so we cannot just return hash literal such as: | |
# { number: thing[:one], url: thing[:two] } | |
hsh[:url] = Nokogiri::HTML.fragment(thing[:two]).at('some_element')[:some_attr] | |
hsh | |
# that `hsh`, `hsh`, `hsh` really annoy me | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If your
map
is really as simple as you show, you can just use a literal hash: