#--
# CREDIT Mikael Brockman
#++

module Kernel

  # A Ruby-ized realization of the K combinator.
  #
  #   with Book.new do |book|
  #     book.title = "Imperium"
  #     book.author = "Ulick Varange"
  #   end
  #
  # Also aliased as #returning for readability.
  #
  #   def foo
  #     returning values = [] do
  #       values << 'bar'
  #       values << 'baz'
  #     end
  #   end
  #
  #   foo # => ['bar', 'baz']

  def with(obj=self)
    yield obj
    obj
  end

  alias :returning :with

end


#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCKernel < Test::Unit::TestCase

    def test_returning
      foo = returning( values = [] ) do
        values << 'bar'
        values << 'baz'
      end
      assert_equal( ['bar', 'baz'], foo )
    end

  end

=end
