diff options
author | Akira Matsuda <ronnie@dio.jp> | 2011-10-02 06:20:58 +0900 |
---|---|---|
committer | Akira Matsuda <ronnie@dio.jp> | 2011-10-05 15:26:28 +0900 |
commit | 9c4fe308b6da76711adffeff24d62acb013680ea (patch) | |
tree | 481b5d8d5526bd0cfbeab2c57cbcafde19235f73 /activesupport/lib/active_support/core_ext/string/output_safety.rb | |
parent | 87c57bb88f0eb1462ed31733ebcf3d9a535d8f16 (diff) | |
download | rails-9c4fe308b6da76711adffeff24d62acb013680ea.tar.gz rails-9c4fe308b6da76711adffeff24d62acb013680ea.tar.bz2 rails-9c4fe308b6da76711adffeff24d62acb013680ea.zip |
override unsafe methods only if defined on String
Diffstat (limited to 'activesupport/lib/active_support/core_ext/string/output_safety.rb')
-rw-r--r-- | activesupport/lib/active_support/core_ext/string/output_safety.rb | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb index 2daf4016cd..e61a27176f 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -142,16 +142,18 @@ module ActiveSupport #:nodoc: end UNSAFE_STRING_METHODS.each do |unsafe_method| - class_eval <<-EOT, __FILE__, __LINE__ + 1 - def #{unsafe_method}(*args, &block) # def capitalize(*args, &block) - to_str.#{unsafe_method}(*args, &block) # to_str.capitalize(*args, &block) - end # end - - def #{unsafe_method}!(*args) # def capitalize!(*args) - @dirty = true # @dirty = true - super # super - end # end - EOT + if 'String'.respond_to?(unsafe_method) + class_eval <<-EOT, __FILE__, __LINE__ + 1 + def #{unsafe_method}(*args, &block) # def capitalize(*args, &block) + to_str.#{unsafe_method}(*args, &block) # to_str.capitalize(*args, &block) + end # end + + def #{unsafe_method}!(*args) # def capitalize!(*args) + @dirty = true # @dirty = true + super # super + end # end + EOT + end end protected |