Rename Object#self to Object#itself to have parity with matz sanctioned method name for Ruby 2.2

上级 702ad710
* Added Object#self which returns the object itself. Useful when dealing with a chaining scenario, like Active Record scopes:
* Added Object#itself which returns the object itself. Useful when dealing with a chaining scenario, like Active Record scopes:
Event.public_send(state.presence_in?([ :trashed, :drafted ]) ? :self).order(:created_at)
Event.public_send(state.presence_in?([ :trashed, :drafted ]) || :itself).order(:created_at)
*DHH*
......
......@@ -2,7 +2,7 @@
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/object/duplicable'
require 'active_support/core_ext/object/deep_dup'
require 'active_support/core_ext/object/self'
require 'active_support/core_ext/object/itself'
require 'active_support/core_ext/object/try'
require 'active_support/core_ext/object/inclusion'
......
class Object
# Returns the object itself. Useful when dealing with a chaining scenario, like Active Record scopes:
#
# Event.public_send(state.presence_in?([ :trashed, :drafted ]) ? :self).order(:created_at)
# Event.public_send(state.presence_in?([ :trashed, :drafted ]) || :itself).order(:created_at)
#
# @return Object
def self
def itself
self
end
end
\ No newline at end of file
......@@ -4,6 +4,6 @@
class Object::SelfTest < ActiveSupport::TestCase
test 'self returns self' do
object = 'fun'
assert_equal object, object.self
assert_equal object, object.itself
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册