Sha256: c838cf02bd8d342ba6e94597cd2cbf12e26927f73d27b3401130840754372b8c

Contents?: true

Size: 671 Bytes

Versions: 10

Compression:

Stored size: 671 Bytes

Contents

module Kernel

  # A Ruby-ized realization of the K combinator.
  #
  #   book_class = Struct.new(:title, :author)
  #
  #   book = returning book_class.new do |book|
  #     book.title = "Imperium"
  #     book.author = "Ulick Varange"
  #   end
  #
  #   book.class  #=> book_class
  #
  # Technically, #returning probably should force the return of
  # the stated object irregardless of any return statements that
  # might appear within it's block. This might differentiate
  # #returning from #with, however it also would require
  # implementation in Ruby itself.
  #
  # CREDIT: Mikael Brockman

  def returning(obj=self) #:yield:
    yield obj
    obj
  end

end

Version data entries

10 entries across 9 versions & 2 rubygems

Version Path
facets-glimmer-3.2.0 lib/core/facets/kernel/returning.rb
facets-3.1.0 lib/core/facets/kernel/returning.rb
facets-3.0.0 lib/core/facets/kernel/returning.rb
facets-2.9.3 lib/core/facets/kernel/returning.rb
facets-2.9.2 src/core/facets/kernel/returning.rb
facets-2.9.2 lib/core/facets/kernel/returning.rb
facets-2.9.1 lib/core/facets/kernel/returning.rb
facets-2.9.0 lib/core/facets/kernel/returning.rb
facets-2.9.0.pre.2 lib/core/facets/kernel/returning.rb
facets-2.9.0.pre.1 lib/core/facets/kernel/returning.rb