Skip to content

Instantly share code, notes, and snippets.

@jonleighton
Created September 19, 2011 11:42
Show Gist options
  • Save jonleighton/1226344 to your computer and use it in GitHub Desktop.
Save jonleighton/1226344 to your computer and use it in GitHub Desktop.
##### Pointless: #####
# Bad:
Foo.new.tap do |foo|
foo.bar = "<3"
end
# Good:
foo = Foo.new
foo.bar = "<3"
foo
# (I prefer the latter because it flows linearly, which it
# should, as the sequence of events is linear.)
##### Just use Enumerable: #####
# Bad:
{}.tap do |hash|
foos.each do |foo|
hash[foo.name] = foo
end
end
# Good:
Hash[foos.map { |foo| [foo.name, foo] }]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment