1 # This file contains implementations of ruby core's custom objects for
2 # serialisation/deserialisation.
4 unless Object.const_defined?(:JSON) and ::JSON.const_defined?(:JSON_LOADED) and
11 def self.json_create(object)
12 if usec = object.delete('u') # used to be tv_usec -> tv_nsec
13 object['n'] = usec * 1000
15 if respond_to?(:tv_nsec)
16 at(*object.values_at('s', 'n'))
18 at(object['s'], object['n'] / 1000)
24 'json_class' => self.class.name,
26 'n' => respond_to?(:tv_nsec) ? tv_nsec : tv_usec * 1000
32 def self.json_create(object)
33 civil(*object.values_at('y', 'm', 'd', 'sg'))
36 alias start sg unless method_defined?(:start)
40 'json_class' => self.class.name,
50 def self.json_create(object)
51 args = object.values_at('y', 'm', 'd', 'H', 'M', 'S')
52 of_a, of_b = object['of'].split('/')
53 if of_b and of_b != '0'
54 args << Rational(of_a.to_i, of_b.to_i)
62 alias start sg unless method_defined?(:start)
66 'json_class' => self.class.name,
80 def self.json_create(object)
86 'json_class' => self.class.name,
87 'a' => [ first, last, exclude_end? ]
93 def self.json_create(object)
98 klass = self.class.name
99 klass.nil? and raise JSON::JSONError, "Only named structs are supported!"
101 'json_class' => klass,
108 def self.json_create(object)
109 result = new(object['m'])
110 result.set_backtrace object['b']
116 'json_class' => self.class.name,
124 def self.json_create(object)
125 new(object['s'], object['o'])
130 'json_class' => self.class.name,