From 260f5a3495771d67ac79074ee34db6566117c7ae Mon Sep 17 00:00:00 2001 From: Eamonn Webster Date: Thu, 8 Feb 2024 23:18:15 +0000 Subject: [PATCH] Plain object, override to_json --- motion/duration.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/motion/duration.rb b/motion/duration.rb index 33d167b..e920dc2 100644 --- a/motion/duration.rb +++ b/motion/duration.rb @@ -3,7 +3,7 @@ module MotionSupport # Time#advance, respectively. It mainly supports the methods on Numeric. # # 1.month.ago # equivalent to Time.now.advance(months: -1) - class Duration < BasicObject + class Duration attr_accessor :value, :parts def initialize(value, parts) #:nodoc: @@ -79,7 +79,11 @@ def as_json(options = nil) #:nodoc: to_i end - protected + def to_json + as_json.to_json + end + + protected def sum(sign, time = ::Time.now) #:nodoc: parts.inject(time) do |t,(type,number)|