aboutsummaryrefslogblamecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/object/acts_like.rb
blob: fcc8e50f06ebd207cd6a8e69d52e7821c5ce5823 (plain) (tree)
1
2
3
4
5
6
7
8
9
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