diff options
author | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-03-09 03:51:39 +0000 |
---|---|---|
committer | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-03-09 03:51:39 +0000 |
commit | 4df71924e47bc0da8bbc3a08f814c48350131585 (patch) | |
tree | 26250b1a2ab441f51e7e8811dbf7416f84b4f929 /ext | |
parent | 095b27946454cec5237e1ce229623e98905a937e (diff) | |
download | ruby-4df71924e47bc0da8bbc3a08f814c48350131585.tar.gz |
* 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.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31075 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/psych/lib/psych/visitors/yaml_tree.rb | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb index 719720a45b..84ebc90a7e 100644 --- a/ext/psych/lib/psych/visitors/yaml_tree.rb +++ b/ext/psych/lib/psych/visitors/yaml_tree.rb @@ -79,15 +79,20 @@ module Psych 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 @@ module Psych # 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 |