diff options
author | Godfrey Chan <godfreykfc@gmail.com> | 2015-05-19 13:27:07 -0700 |
---|---|---|
committer | Godfrey Chan <godfreykfc@gmail.com> | 2015-05-19 13:29:02 -0700 |
commit | 046936481903dc46f48c81bd74eec4052624e40c (patch) | |
tree | 031c9d31ae2d394136ac2a6deef709f713563180 /activesupport | |
parent | af53280a4b5b3323ac87dc60deb2b1b781197b2b (diff) | |
download | rails-046936481903dc46f48c81bd74eec4052624e40c.tar.gz rails-046936481903dc46f48c81bd74eec4052624e40c.tar.bz2 rails-046936481903dc46f48c81bd74eec4052624e40c.zip |
Small stylistic tweaks for `Delegator#try` patch
* Rename `ActiveSupport::Try` => `ActiveSupport::Tryable`
* Include the modules inline
* `private` indentation
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/core_ext/object/try.rb | 10 | ||||
-rw-r--r-- | activesupport/test/core_ext/object/try_test.rb | 30 |
2 files changed, 20 insertions, 20 deletions
diff --git a/activesupport/lib/active_support/core_ext/object/try.rb b/activesupport/lib/active_support/core_ext/object/try.rb index 6605771d90..69be6c4abc 100644 --- a/activesupport/lib/active_support/core_ext/object/try.rb +++ b/activesupport/lib/active_support/core_ext/object/try.rb @@ -1,7 +1,7 @@ require 'delegate' module ActiveSupport - module Try #:nodoc: + module Tryable #:nodoc: def try(*a, &b) try!(*a, &b) if a.empty? || respond_to?(a.first) end @@ -20,11 +20,9 @@ module ActiveSupport end end -[Object, Delegator].each do |klass| - klass.include(ActiveSupport::Try) -end - class Object + include ActiveSupport::Tryable + ## # :method: try # @@ -105,6 +103,8 @@ class Object end class Delegator + include ActiveSupport::Tryable + ## # :method: try # diff --git a/activesupport/test/core_ext/object/try_test.rb b/activesupport/test/core_ext/object/try_test.rb index cdb76af1ac..5ea0f0eca6 100644 --- a/activesupport/test/core_ext/object/try_test.rb +++ b/activesupport/test/core_ext/object/try_test.rb @@ -77,9 +77,9 @@ class ObjectTryTest < ActiveSupport::TestCase klass = Class.new do private - def private_method - 'private method' - end + def private_method + 'private method' + end end assert_raise(NoMethodError) { klass.new.try!(:private_method) } @@ -89,9 +89,9 @@ class ObjectTryTest < ActiveSupport::TestCase klass = Class.new do private - def private_method - 'private method' - end + def private_method + 'private method' + end end assert_nil klass.new.try(:private_method) @@ -108,9 +108,9 @@ class ObjectTryTest < ActiveSupport::TestCase private - def private_delegator_method - 'private delegator method' - end + def private_delegator_method + 'private delegator method' + end end def test_try_with_method_on_delegator @@ -139,9 +139,9 @@ class ObjectTryTest < ActiveSupport::TestCase klass = Class.new do private - def private_method - 'private method' - end + def private_method + 'private method' + end end assert_nil Decorator.new(klass.new).try(:private_method) @@ -151,9 +151,9 @@ class ObjectTryTest < ActiveSupport::TestCase klass = Class.new do private - def private_method - 'private method' - end + def private_method + 'private method' + end end assert_raise(NoMethodError) do |