J
John-Mason P. Shackelford
Why does the YAML library add a 'mesg' instance variable instead of
re-implementing Exception#message to return @message? Any reason why
we don't preserve the backtrace as well? (Relevant YAML code excepted
below.)
# File yaml/rubytypes.rb
YAML.add_ruby_type( /^exception/ ) { |type, val|
type, obj_class =3D YAML.read_type_class( type, Exception )
o =3D YAML.object_maker( obj_class, { 'mesg' =3D> val.delete( 'message'=
) } )
val.each_pair { |k,v|
=09=09o.instance_variable_set("@#{k}", v)
=09}
=09o
}
# File yaml/rubytypes.rb, line 119
def Exception.yaml_new( klass, tag, val )
o =3D YAML.object_maker( klass, { 'mesg' =3D> val.delete( 'message'=
) } )
val.each_pair do |k,v|
o.instance_variable_set("@#{k}", v)
end
o
end
Is the best way for me to support this functionality for a particular
exception to call YAML.add_ruby_type() and to implement #to_yaml and
#yaml_new methods on my exception?
Thanks!
John-Mason Shackelford
Software Developer
Pearson Educational Measurement
2510 North Dodge St.
Iowa City, IA 52245
ph. 319-354-9200x6214
(e-mail address removed)
http://pearsonedmeasurement.com
re-implementing Exception#message to return @message? Any reason why
we don't preserve the backtrace as well? (Relevant YAML code excepted
below.)
# File yaml/rubytypes.rb
YAML.add_ruby_type( /^exception/ ) { |type, val|
type, obj_class =3D YAML.read_type_class( type, Exception )
o =3D YAML.object_maker( obj_class, { 'mesg' =3D> val.delete( 'message'=
) } )
val.each_pair { |k,v|
=09=09o.instance_variable_set("@#{k}", v)
=09}
=09o
}
# File yaml/rubytypes.rb, line 119
def Exception.yaml_new( klass, tag, val )
o =3D YAML.object_maker( klass, { 'mesg' =3D> val.delete( 'message'=
) } )
val.each_pair do |k,v|
o.instance_variable_set("@#{k}", v)
end
o
end
Is the best way for me to support this functionality for a particular
exception to call YAML.add_ruby_type() and to implement #to_yaml and
#yaml_new methods on my exception?
Thanks!
John-Mason Shackelford
Software Developer
Pearson Educational Measurement
2510 North Dodge St.
Iowa City, IA 52245
ph. 319-354-9200x6214
(e-mail address removed)
http://pearsonedmeasurement.com