Sha256: 792a55f382d5e8b5b07871317ace2a8ac1ea5125f0ec1c35ea92efdc926fb616

Contents?: true

Size: 473 Bytes

Versions: 2

Compression:

Stored size: 473 Bytes

Contents

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
facets-1.8.51 lib/facets/core/kernel/tap.rb
facets-1.8.54 lib/facets/core/kernel/tap.rb