From 64d91122222c11ad3918cc8e2e3ebc4b0a03448a Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 1 Aug 2014 10:30:13 -0700 Subject: Rename Object#self to Object#itself to have parity with matz sanctioned method name for Ruby 2.2 --- activesupport/CHANGELOG.md | 4 ++-- activesupport/lib/active_support/core_ext/object.rb | 2 +- activesupport/lib/active_support/core_ext/object/itself.rb | 10 ++++++++++ activesupport/lib/active_support/core_ext/object/self.rb | 10 ---------- activesupport/test/core_ext/object/itself_test.rb | 9 +++++++++ activesupport/test/core_ext/object/self_test.rb | 9 --------- 6 files changed, 22 insertions(+), 22 deletions(-) create mode 100644 activesupport/lib/active_support/core_ext/object/itself.rb delete mode 100644 activesupport/lib/active_support/core_ext/object/self.rb create mode 100644 activesupport/test/core_ext/object/itself_test.rb delete mode 100644 activesupport/test/core_ext/object/self_test.rb diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index cb57ad0e0a..72fa6722b5 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,6 +1,6 @@ -* 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* diff --git a/activesupport/lib/active_support/core_ext/object.rb b/activesupport/lib/active_support/core_ext/object.rb index 2646342b2e..f1106cca9b 100644 --- a/activesupport/lib/active_support/core_ext/object.rb +++ b/activesupport/lib/active_support/core_ext/object.rb @@ -2,7 +2,7 @@ require 'active_support/core_ext/object/acts_like' 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' diff --git a/activesupport/lib/active_support/core_ext/object/itself.rb b/activesupport/lib/active_support/core_ext/object/itself.rb new file mode 100644 index 0000000000..df613c4e4f --- /dev/null +++ b/activesupport/lib/active_support/core_ext/object/itself.rb @@ -0,0 +1,10 @@ +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 + end +end \ No newline at end of file diff --git a/activesupport/lib/active_support/core_ext/object/self.rb b/activesupport/lib/active_support/core_ext/object/self.rb deleted file mode 100644 index 5c51bf56c9..0000000000 --- a/activesupport/lib/active_support/core_ext/object/self.rb +++ /dev/null @@ -1,10 +0,0 @@ -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 diff --git a/activesupport/test/core_ext/object/itself_test.rb b/activesupport/test/core_ext/object/itself_test.rb new file mode 100644 index 0000000000..0885fe91e3 --- /dev/null +++ b/activesupport/test/core_ext/object/itself_test.rb @@ -0,0 +1,9 @@ +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.itself + end +end diff --git a/activesupport/test/core_ext/object/self_test.rb b/activesupport/test/core_ext/object/self_test.rb deleted file mode 100644 index 751199e41c..0000000000 --- a/activesupport/test/core_ext/object/self_test.rb +++ /dev/null @@ -1,9 +0,0 @@ -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 -- cgit v1.2.3