Only define Objetc#itself when it is not defined

Ruby 2.2 will include Kernel#itself so we don't need to define again.

See
https://github.com/ruby/ruby/commit/0a0160d6b659f6131a525fe1579e7c463d4c197e
上级 7521b8ec
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 ]) || :itself).order(:created_at)
#
# @return Object
def itself
self
unless respond_to?(:itself) # TODO: Remove this file when we drop support to Ruby < 2.2
# Returns the object itself. Useful when dealing with a chaining scenario, like Active Record scopes:
#
# Event.public_send(state.presence_in?([ :trashed, :drafted ]) || :itself).order(:created_at)
#
# @return Object
def itself
self
end
end
end
\ No newline at end of file
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册