Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 5952

Show
Ignore:
Timestamp:
01/15/07 17:13:45 (2 years ago)
Author:
minam
Message:

change Duration to use the new Object#acts_like? helper to do duck typing

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activesupport/lib/active_support/duration.rb

    r5948 r5952  
    6666    def sum(sign, time = ::Time.now) #:nodoc: 
    6767      parts.inject(time) do |t,(type,number)| 
    68         if t.respond_to?(:sec) # quacks like a Time 
     68        if t.acts_like?(:time) 
    6969          if type == :seconds 
    7070            t + (sign * number) 
     
    7272            t.advance(type => sign * number) 
    7373          end 
    74         elsif t.respond_to?(:day) # quacks like a Date 
     74        elsif t.acts_like?(:date) 
    7575          raise ArgumentError, "Adding seconds to a Date does not make sense" if type == :seconds 
    7676          t.advance(type => sign * number)