Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make sure Duration uses duck-typing instead of explicit classes, so a…

…pps can pass proxy objects around and have it all "just work"

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5948 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 8368e160b4acddf0204a84a9f8d360dcd99fe0ce 1 parent d1917cf
Jamis Buck jamis authored
Showing with 4 additions and 3 deletions.
  1. +4 −3 activesupport/lib/active_support/duration.rb
7 activesupport/lib/active_support/duration.rb
View
@@ -65,16 +65,17 @@ def inspect #:nodoc:
def sum(sign, time = ::Time.now) #:nodoc:
parts.inject(time) do |t,(type,number)|
- case t
- when ::Time
+ if t.respond_to?(:sec) # quacks like a Time
if type == :seconds
t + (sign * number)
else
t.advance(type => sign * number)
end
- when ::Date
+ elsif t.respond_to?(:day) # quacks like a Date
raise ArgumentError, "Adding seconds to a Date does not make sense" if type == :seconds
t.advance(type => sign * number)
+ else
+ raise ArgumentError, "expected a time or date, got #{time.inspect}"
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.