Method: Kernel#returning
- Defined in:
- lib/core/facets/kernel/returning.rb
#returning(obj = self) {|obj| ... } ⇒ Object
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. = "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
22 23 24 25 |
# File 'lib/core/facets/kernel/returning.rb', line 22 def returning(obj=self) #:yield: yield obj obj end |