lib/active_support/duration.rb in activesupport-4.2.0.beta1 vs lib/active_support/duration.rb in activesupport-4.2.0.beta2

- old
+ new

@@ -5,11 +5,11 @@ module ActiveSupport # Provides accurate date and time measurements using Date#advance and # Time#advance, respectively. It mainly supports the methods on Numeric. # # 1.month.ago # equivalent to Time.now.advance(months: -1) - class Duration < ProxyObject + class Duration attr_accessor :value, :parts def initialize(value, parts) #:nodoc: @value, @parts = value, parts end @@ -37,22 +37,32 @@ def is_a?(klass) #:nodoc: Duration == klass || value.is_a?(klass) end alias :kind_of? :is_a? + def instance_of?(klass) # :nodoc: + Duration == klass || value.instance_of?(klass) + end + # Returns +true+ if +other+ is also a Duration instance with the # same +value+, or if <tt>other == value</tt>. def ==(other) if Duration === other other.value == value else other == value end end + def to_s + @value.to_s + end + + # Returns +true+ if +other+ is also a Duration instance, which has the + # same parts as this one. def eql?(other) - other.is_a?(Duration) && self == other + Duration === other && other.value.eql?(value) end def self.===(other) #:nodoc: other.is_a?(Duration) rescue ::NoMethodError @@ -81,9 +91,13 @@ to_sentence(:locale => :en) end def as_json(options = nil) #:nodoc: to_i + end + + def respond_to_missing?(method, include_private=false) #:nodoc + @value.respond_to?(method, include_private) end protected def sum(sign, time = ::Time.current) #:nodoc: