235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
# File 'lib/ron.rb', line 235
def to_ron_list2(session=Ron::Session.new)
respond_to? :to_ron_list or return [to_ron]
if pair=(session.objects_in_progress.assoc __id__)
str=pair[1]
if str[/^Recursive\(/]
result=pair.last else
pair.push result=Ron.gen_local_name
str[0,0]="Recursive(#{result}={}, "
end
result=[result]
elsif pair=session.objects_seen[ __id__ ]
str=pair.first
if str[/^[a-z_0-9]+=[^=]/i]
result=pair.last else
pair.push result=Ron.gen_local_name
str[0,0]=result+"="
end
result=[result]
else
str=''
session.objects_in_progress.push [__id__,str]
result=to_ron_list(session).unshift str
if result.last=="}#end object literal"
result.last.replace "}"
was_obj_syntax=true
else
ivars=instance_variables
ivars.map!{|iv| iv.to_s } if Symbol===ivars.first
ivars-=::Ron::IGNORED_INSTANCE_VARIABLES[self.class.name]
ivars.empty? or result.push ".with_ivars(", *ivars.map{|iv|
[":",iv.to_s,"=>",instance_variable_get(iv).to_ron_list2(session),', ']
}.flatten[0...-1]<<")"
end
extensions=Ron::extension_modules_of(self)
unless extensions.empty?
result=["(",result,")"] if was_obj_syntax
result.push ".extend(",extensions,")"
end
result.push ")" if str[/^Recursive\(/]
session.objects_seen[__id__]=[session.objects_in_progress.pop[1]]
result
end
result
end
|