Added Object#self which returns the object itself

上级 20405e51
* Added Object#self 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)
*DHH*
* `Object#with_options` executes block in merging option context when
explicit receiver in not passed.
......
......@@ -2,6 +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/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)
#
# @return Object
def self
self
end
end
\ No newline at end of file
require 'abstract_unit'
require 'active_support/core_ext/object'
class Object::SelfTest < ActiveSupport::TestCase
test 'self returns self' do
object = 'fun'
assert_equal object, object.self
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册