Sha256: b9a1e59e09a2151b654bd202b7943bd8fa68e7de462db8b3c7c88dd92508d8f5

Contents?: true

Size: 1.03 KB

Versions: 7

Compression:

Stored size: 1.03 KB

Contents

module Kernel

  unless method_defined?(:tap)  # 1.8.7+

    # The tap K-Combinator. This yields self -and- returns self.
    #
    # Note, Ruby 1.9+ does not support the zero arity #instance_eval
    # variation so it has been deprecated.
    def tap #:yield:
      yield(self)
      self
    end

    #--
    # == Old definition
    #
    #
    #   def tap #:yield:
    #     if block_given?
    #       b.arity == 1 ? yield(self) : instance_eval(&b)
    #     end
    #     return self
    #   end
    #
    # == Future definition?
    #
    # This is a consideration for a future #tap using Functor:
    #
    #   require 'facets/functor'
    #
    #   def tap(&b)
    #     if block_given?
    #       b.arity == 1 ? yield(self) : instance_eval(&b)
    #       self
    #     else
    #       Functor.new{ |op, *args| self.send(op, *args); self }
    #     end
    #   end
    #
    # It would allow a single call, before returning the original.
    # However there are not very many useful things you can do with
    # that.
    #++

  end

end

Version data entries

7 entries across 6 versions & 1 rubygems

Version Path
facets-2.9.3 lib/core/facets/kernel/tap.rb
facets-2.9.2 src/core/facets/kernel/tap.rb
facets-2.9.2 lib/core/facets/kernel/tap.rb
facets-2.9.1 lib/core/facets/kernel/tap.rb
facets-2.9.0 lib/core/facets/kernel/tap.rb
facets-2.9.0.pre.2 lib/core/facets/kernel/tap.rb
facets-2.9.0.pre.1 lib/core/facets/kernel/tap.rb