hoangdangninh
7/12/2017 - 8:26 PM

syntactic sugar blocks in ruby

syntactic sugar blocks in ruby

user = User.new.tap do |u|
  u.username = "foobar"
  u.save!
end

# has a much better intent than this

user = User.new
user.username = "foobar"
user.save!
5.upto(10) { |i| puts i }

# same as

5.upto(10) do |i| 
   puts i
end