ruby-changes:19037
From: tenderlove <ko1@a...>
Date: Wed, 9 Mar 2011 20:50:02 +0900 (JST)
Subject: [ruby-changes:19037] Ruby:r31075 (trunk): * ext/psych/lib/psych/visitors/yaml_tree.rb: Rescue exceptions when
tenderlove 2011-03-09 12:51:39 +0900 (Wed, 09 Mar 2011) New Revision: 31075 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=31075 Log: * ext/psych/lib/psych/visitors/yaml_tree.rb: Rescue exceptions when people implement the method method. Thanks Lin Jen-Shin. [ruby-core:35255] * test/psych/visitors/test_yaml_tree.rb: test for implementation of method method. Modified files: trunk/ChangeLog trunk/ext/psych/lib/psych/visitors/yaml_tree.rb trunk/test/psych/visitors/test_yaml_tree.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 31074) +++ ChangeLog (revision 31075) @@ -1,3 +1,12 @@ +Wed Mar 9 12:50:24 2011 Aaron Patterson <aaron@t...> + + * ext/psych/lib/psych/visitors/yaml_tree.rb: Rescue exceptions when + people implement the method method. Thanks Lin Jen-Shin. + [ruby-core:35255] + + * test/psych/visitors/test_yaml_tree.rb: test for implementation of + method method. + Wed Mar 9 11:53:31 2011 NARUSE, Yui <naruse@r...> * enc/shift_jis.c: Change SJIS as an alias of Windows-31J. Index: ext/psych/lib/psych/visitors/yaml_tree.rb =================================================================== --- ext/psych/lib/psych/visitors/yaml_tree.rb (revision 31074) +++ ext/psych/lib/psych/visitors/yaml_tree.rb (revision 31075) @@ -79,15 +79,20 @@ end if target.respond_to?(:to_yaml) - loc = target.method(:to_yaml).source_location.first - if loc !~ /(syck\/rubytypes.rb|psych\/core_ext.rb)/ - unless target.respond_to?(:encode_with) - if $VERBOSE - warn "implementing to_yaml is deprecated, please implement \"encode_with\"" + begin + loc = target.method(:to_yaml).source_location.first + if loc !~ /(syck\/rubytypes.rb|psych\/core_ext.rb)/ + unless target.respond_to?(:encode_with) + if $VERBOSE + warn "implementing to_yaml is deprecated, please implement \"encode_with\"" + end + + target.to_yaml(:nodump => true) end - - target.to_yaml(:nodump => true) end + rescue + # public_method or source_location might be overridden, + # and it's OK to skip it since it's only to emit a warning end end @@ -300,12 +305,17 @@ # FIXME: remove this method once "to_yaml_properties" is removed def find_ivars target - loc = target.method(:to_yaml_properties).source_location.first - unless loc.start_with?(Psych::DEPRECATED) || loc.end_with?('rubytypes.rb') - if $VERBOSE - warn "#{loc}: to_yaml_properties is deprecated, please implement \"encode_with(coder)\"" + begin + loc = target.method(:to_yaml_properties).source_location.first + unless loc.start_with?(Psych::DEPRECATED) || loc.end_with?('rubytypes.rb') + if $VERBOSE + warn "#{loc}: to_yaml_properties is deprecated, please implement \"encode_with(coder)\"" + end + return target.to_yaml_properties end - return target.to_yaml_properties + rescue + # public_method or source_location might be overridden, + # and it's OK to skip it since it's only to emit a warning. end target.instance_variables Index: test/psych/visitors/test_yaml_tree.rb =================================================================== --- test/psych/visitors/test_yaml_tree.rb (revision 31074) +++ test/psych/visitors/test_yaml_tree.rb (revision 31075) @@ -38,6 +38,12 @@ assert_equal s.foo, obj.foo end + def test_override_method + s = Struct.new(:method).new('override') + obj = Psych.load(Psych.dump(s)) + assert_equal s.method, obj.method + end + def test_exception ex = Exception.new 'foo' loaded = Psych.load(Psych.dump(ex)) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/