
module Kernel

  # Yield self and return self.

  def tap &b
    if b.arity == 1
      yield self
    else
      instance_eval(&b)
    end

    return self
  end

end




=begin test

  require 'test/unit'

  class TestTap < Test::Unit::TestCase

    def test_tap
      x = "foo"
      r = ("foobar".tap{ gsub! /bar/, '' })
      assert_equal(x, r)
    end

    def test_tap_array
      x = [1,2,3]
      x.tap{ |a|
        assert_equal(x, a)
      }
    end
  end

=end

