Created
September 25, 2013 19:54
-
-
Save aergonaut/6705119 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
# use tap to modify an object and then return it immediately | |
# before... | |
def foo | |
obj = Foo.new | |
obj.attribute = :value | |
obj | |
end | |
# after... | |
def foo | |
Foo.new.tap do |obj| | |
obj.attribute = :value | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment