I've been looking around for the easiest solution to convert all Datetime values to ISO 8601 when sending them to a specific requester from an API. I was able to monkey patch Time#to_json
with the following:
class Time
def to_json(options = {})
self.iso8601.to_json
end
end
And require the file in the before
callback of Grape when params showed the request was coming from the desired location.
Is this the best way to accomplish this? Could I instead be doing something in the after
callback of Grape to loop through my data and convert the values there? Monkey patching Time#to_json
gets the job done, but feels funny to me. Though I am new to Ruby.