aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2017-10-23 15:59:02 -0400
committerGitHub <noreply@github.com>2017-10-23 15:59:02 -0400
commitec7bf399b12c8aea6d506106cc5408f2f17ed349 (patch)
treed51ed4a05e749fe71494ceb41bb372a1335428ce /activesupport/lib
parent9c5c0596f137c396b6356416a3f92a3a082c53f6 (diff)
parenta5c9f24603da478366a7fa1a1279f13501e30bbe (diff)
downloadrails-ec7bf399b12c8aea6d506106cc5408f2f17ed349.tar.gz
rails-ec7bf399b12c8aea6d506106cc5408f2f17ed349.tar.bz2
rails-ec7bf399b12c8aea6d506106cc5408f2f17ed349.zip
Merge pull request #30961 from q-centrix/performance-improvement-acts-like
Performance improvements for acts_like? method
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/object/acts_like.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/object/acts_like.rb b/activesupport/lib/active_support/core_ext/object/acts_like.rb
index 2eb72f6b3a..403ee20e39 100644
--- a/activesupport/lib/active_support/core_ext/object/acts_like.rb
+++ b/activesupport/lib/active_support/core_ext/object/acts_like.rb
@@ -7,6 +7,15 @@ class Object
# <tt>x.acts_like?(:date)</tt> to do duck-type-safe comparisons, since classes that
# we want to act like Time simply need to define an <tt>acts_like_time?</tt> method.
def acts_like?(duck)
- respond_to? :"acts_like_#{duck}?"
+ case duck
+ when :time
+ respond_to? :acts_like_time?
+ when :date
+ respond_to? :acts_like_date?
+ when :string
+ respond_to? :acts_like_string?
+ else
+ respond_to? :"acts_like_#{duck}?"
+ end
end
end