diff options
Diffstat (limited to 'activesupport/lib/active_support/core_ext/object/acts_like.rb')
-rw-r--r-- | activesupport/lib/active_support/core_ext/object/acts_like.rb | 10 |
1 files changed, 10 insertions, 0 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 new file mode 100644 index 0000000000..fcc8e50f06 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/object/acts_like.rb @@ -0,0 +1,10 @@ +class Object + # A duck-type assistant method. For example, Active Support extends Date + # to define an acts_like_date? method, and extends Time to define + # acts_like_time?. As a result, we can do "x.acts_like?(:time)" and + # "x.acts_like?(:date)" to do duck-type-safe comparisons, since classes that + # we want to act like Time simply need to define an acts_like_time? method. + def acts_like?(duck) + respond_to? :"acts_like_#{duck}?" + end +end |