title: advantage of tap method in ruby
body: <p>I was just reading a blog article and noticed that the author used <code>tap</code> in a snippet something like:</p>
  <pre class="lang-ruby prettyprint-override"><code>user = User.new.tap do |u|
    u.username = &quot;foobar&quot;
    u.save!
  end
  </code></pre>
  <p>My question is what exactly is the benefit or advantage of using <code>tap</code>? Couldn't I just do:</p>
  <pre class="lang-ruby prettyprint-override"><code>user = User.new
  user.username = &quot;foobar&quot;
  user.save!
  </code></pre>
  <p>or better yet:</p>
  <pre class="lang-ruby prettyprint-override"><code>user = User.create! username: &quot;foobar&quot;
  </code></pre>