Module: Duration::Arithmetic
- Included in:
- Duration
- Defined in:
- lib/duration/arithmetic.rb
Instance Method Summary collapse
Instance Method Details
#+(other_duration) ⇒ Object
3 4 5 6 7 |
# File 'lib/duration/arithmetic.rb', line 3 def + other_duration raise StandardError.new("Cannot add #{other_duration.class} to #{self}") unless other_duration.respond_to?(:to_i) other_duration = other_duration.to_duration if other_duration.respond_to?(:to_duration) Duration.new(self.to_i + other_duration.to_i) end |
#-(other_duration) ⇒ Object
9 10 11 12 13 |
# File 'lib/duration/arithmetic.rb', line 9 def - other_duration raise StandardError.new("Cannot subtract #{other_duration.class} from #{self}") unless other_duration.respond_to?(:to_i) other_duration = other_duration.to_duration if other_duration.respond_to?(:to_duration) Duration.new(self.to_i - other_duration.to_i) end |