From a2932784bb71e72a78c32819ebd7ed2bed551e3e Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sun, 5 Oct 2008 22:16:26 +0100 Subject: Merge docrails --- .../lib/active_support/core_ext/object/misc.rb | 52 +++++++++++++++------- 1 file changed, 36 insertions(+), 16 deletions(-) (limited to 'activesupport/lib/active_support/core_ext/object/misc.rb') diff --git a/activesupport/lib/active_support/core_ext/object/misc.rb b/activesupport/lib/active_support/core_ext/object/misc.rb index 06a7d05702..cd0a04d32a 100644 --- a/activesupport/lib/active_support/core_ext/object/misc.rb +++ b/activesupport/lib/active_support/core_ext/object/misc.rb @@ -1,30 +1,50 @@ class Object - # A Ruby-ized realization of the K combinator, courtesy of Mikael Brockman. + # Returns +value+ after yielding +value+ to the block. This simplifies the + # process of constructing an object, performing work on the object, and then + # returning the object from a method. It is a Ruby-ized realization of the K + # combinator, courtesy of Mikael Brockman. # - # def foo - # returning values = [] do - # values << 'bar' - # values << 'baz' - # end - # end + # ==== Examples # - # foo # => ['bar', 'baz'] + # # Without returning + # def foo + # values = [] + # values << "bar" + # values << "baz" + # return values + # end # - # def foo - # returning [] do |values| - # values << 'bar' - # values << 'baz' - # end - # end + # foo # => ['bar', 'baz'] # - # foo # => ['bar', 'baz'] + # # returning with a local variable + # def foo + # returning values = [] do + # values << 'bar' + # values << 'baz' + # end + # end # + # foo # => ['bar', 'baz'] + # + # # returning with a block argument + # def foo + # returning [] do |values| + # values << 'bar' + # values << 'baz' + # end + # end + # + # foo # => ['bar', 'baz'] def returning(value) yield(value) value end - # An elegant way to refactor out common options + # An elegant way to factor duplication out of options passed to a series of + # method calls. Each method called in the block, with the block variable as + # the receiver, will have its options merged with the default +options+ hash + # provided. Each method called on the block variable must take an options + # hash as its final argument. # # with_options :order => 'created_at', :class_name => 'Comment' do |post| # post.has_many :comments, :conditions => ['approved = ?', true], :dependent => :delete_all -- cgit v1.2.3