Object
Time serialization/deserialization
Deserializes JSON string by converting time since epoch to Time
# File lib/json/add/time.rb, line 9 9: def self.json_create(object) 10: if usec = object.delete('u') # used to be tv_usec -> tv_nsec 11: object['n'] = usec * 1000 12: end 13: if instance_methods.include?(:tv_nsec) 14: at(object['s'], Rational(object['n'], 1000)) 15: else 16: at(object['s'], object['n'] / 1000) 17: end 18: end
Returns a hash, that will be turned into a JSON object and represent this object.
# File lib/json/add/time.rb, line 22 22: def as_json(*) 23: nanoseconds = [ tv_usec * 1000 ] 24: respond_to?(:tv_nsec) and nanoseconds << tv_nsec 25: nanoseconds = nanoseconds.max 26: { 27: JSON.create_id => self.class.name, 28: 's' => tv_sec, 29: 'n' => nanoseconds, 30: } 31: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.