public Method

Object.acts_like?(duck)

A duck-type assistant method. For example, ActiveSupport 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.

Source Code

# File active_support/core_ext/object/misc.rb, line 56
def acts_like?(duck)
  respond_to? "acts_like_#{duck}?"
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.