提交 5314960d 编写于 作者: J Jamis Buck

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


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5952 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 f28eef9a
......@@ -65,13 +65,13 @@ def inspect #:nodoc:
def sum(sign, time = ::Time.now) #:nodoc:
parts.inject(time) do |t,(type,number)|
if t.respond_to?(:sec) # quacks like a Time
if t.acts_like?(:time)
if type == :seconds
t + (sign * number)
else
t.advance(type => sign * number)
end
elsif t.respond_to?(:day) # quacks like a Date
elsif t.acts_like?(:date)
raise ArgumentError, "Adding seconds to a Date does not make sense" if type == :seconds
t.advance(type => sign * number)
else
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册