Permalink
Browse files

Object#returning removed

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent f4200b0 commit b0b9bf320409b66c6c6b680371aca590297cd4cc @spastorino spastorino committed with josevalim Jul 25, 2010
@@ -1,4 +1,4 @@
-require 'active_support/core_ext/object/misc'
+require 'active_support/core_ext/object/with_options'
module MyApplication
module Business
@@ -7,7 +7,6 @@
require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/module/aliasing'
require 'active_support/core_ext/object/blank'
-require 'active_support/core_ext/object/misc'
require 'active_support/core_ext/object/to_query'
require 'active_support/core_ext/object/duplicable'
require 'set'
@@ -5,9 +5,7 @@
require 'active_support/core_ext/object/conversions'
require 'active_support/core_ext/object/instance_variables'
-require 'active_support/core_ext/object/misc'
-require 'active_support/core_ext/object/returning'
require 'active_support/core_ext/object/to_json'
require 'active_support/core_ext/object/to_param'
require 'active_support/core_ext/object/to_query'
@@ -1,2 +0,0 @@
-require 'active_support/core_ext/object/returning'
-require 'active_support/core_ext/object/with_options'
@@ -1,42 +0,0 @@
-class Object
- # 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.
- #
- # ==== Examples
- #
- # # Without returning
- # def foo
- # values = []
- # values << "bar"
- # values << "baz"
- # return values
- # end
- #
- # 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
-end
@@ -1,5 +1,5 @@
require 'abstract_unit'
-require 'active_support/core_ext/object/misc'
+require 'active_support/core_ext/object/with_options'
class OptionMergerTest < Test::Unit::TestCase
def setup
@@ -1,4 +1,3 @@
-require "active_support/core_ext/object/misc"
require "cgi"
require "active_support/core_ext/cgi"

21 comments on commit b0b9bf3

Contributor

josh-m-sharpe replied Jul 26, 2010

I'm curious to know what the rational is behind this?

Contributor

rohit replied Jul 26, 2010

You can now use tap.

Member

amatsuda replied Jul 26, 2010

This is a very sad news.
Object#returning could actually be rewritten by Object#tap, but both methods are not the same.
I prefer using Object#returning than tap in a particular context such as "returning" an object, since this apparently provides better readability.

Contributor

iain replied Jul 26, 2010

Shouldn't it be deprecated some time before actually removing it?

Contributor

josevalim replied Jul 26, 2010

Deprecated on 2-3-stable.

Contributor

iain replied Jul 26, 2010

In that case: bye!

I loved it :(

Member

amatsuda replied Jul 27, 2010

FYI, this actually caused several problems on other products depending on AS.
rspec-rails http://github.com/rspec/rspec-rails/commit/6c79c0d8a6bd8b9997521ce1317f53e1380ee52a
Haml http://github.com/nex3/haml/commit/4207b1fb5ea4f1b3ba460a2230d5bbd578be953c

Now, library authors should notice that you never should use returning nor tap in order to let your product work on both Rails 3 and Rails < 2.3 + Ruby 1.8.6.

Contributor

dmathieu replied Jul 27, 2010

I think it should be deprecated in 3, to be removed in 3.1. And not only in 2.3.

If for any reason you have plugins that fail because of this change insert this initializer:

class Object
  def returning(object, &block)
    tap do
      yield block
      return object
    end
  end
end
Contributor

radar replied Jul 28, 2010

@foeken Why? Why not just switch to using tap?

Contributor

dmathieu replied Jul 28, 2010

@radar > @foeken says he's using this because some plugins are using returning and failing now.
The other solution would be to fork the plugin and change the returning occurences to tap.

exactly, I don't want to fork the plugin for a one line change, I mailed the developer and added this to keep it working until they fix it :)

Contributor

schof replied Aug 1, 2010

Did we really need to drop this method when moving from beta4 to rc? IMHO this could've also waited until more widespread use of Ruby 1.9. What's the big rush?

Contributor

schof replied Aug 1, 2010

By the way this was deprecated the same day as it was removed and the deprecated code was never even released.

Contributor

bensie replied Aug 2, 2010

@schof Object#tap requires a minimum of 1.8.7, which is the same requirement as Rails 3. Deprecated code was added to 2-3-stable.

Contributor

ryanb replied Aug 2, 2010

I agree this should be deprecated in 3.0 and removed in 3.1. Plugin developers had no warning about this change so right now their plugins are broken for Rails 3. This just adds another problem every developer has to deal with when they try to upgrade to Rails 3.

This is too quick to be removed.....

Contributor

bensie replied Aug 2, 2010

It was just brought back in 88b5f93

Contributor

schof replied Aug 2, 2010

I didn't realize that tap was supported in 1.8.7 - since it is, then no problem with deprecating and then requiring in 3.1. Thanks for listening.

I think it's better to remove 'returning' first in your application if you didnt patch back in to Rails 3 RC, tap don't work very well

Please sign in to comment.