Skip to content

Instantly share code, notes, and snippets.

@theHamdiz
Created February 17, 2016 00:26
Show Gist options
  • Select an option

  • Save theHamdiz/96013379c49744336133 to your computer and use it in GitHub Desktop.

Select an option

Save theHamdiz/96013379c49744336133 to your computer and use it in GitHub Desktop.
Use the #tap method to initialize your objects beautifully and elegantly instead of setting various properties manually.
class User
attr_accessor :a, :b, :c
end
# basically the tap method yields the calling object
# to the block and returns it back
user = User.new.tap do |u|
u.a = 1
u.b = 2
u.c = 3
end
p user
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment