Skip to content

Instantly share code, notes, and snippets.

@timriley
Forked from lachie/gist:203539
Created October 11, 2009 11:57

Revisions

  1. @lachie lachie created this gist Oct 6, 2009.
    19 changes: 19 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    require 'pp'

    class Object
    def tap
    yield self
    self
    end
    def tapp
    pp self
    self
    end
    end

    a = [nil, :apple, [:others]].flatten.tapp.compact.tapp
    #> [nil, :apple, :others]
    #> [:apple, :others]

    a.tapp
    #> [:apple, :others]