Permalink
Browse files

override unsafe methods only if defined on String

  • Loading branch information...
1 parent 87bbf48 commit 984d03149080628ed3c628a12b90cbbb6b2bb50f @amatsuda amatsuda committed with spastorino Oct 1, 2011
Showing with 12 additions and 10 deletions.
  1. +12 −10 activesupport/lib/active_support/core_ext/string/output_safety.rb
@@ -130,16 +130,18 @@ def to_yaml(*args)
end
for unsafe_method in UNSAFE_STRING_METHODS
- class_eval <<-EOT, __FILE__, __LINE__
- def #{unsafe_method}(*args)
- super.to_str
- end
-
- def #{unsafe_method}!(*args)
- @dirty = true
- super
- end
- EOT
+ if 'String'.respond_to?(unsafe_method)
+ class_eval <<-EOT, __FILE__, __LINE__ + 1
+ def #{unsafe_method}(*args)
+ super.to_str
+ end
+
+ def #{unsafe_method}!(*args)
+ @dirty = true
+ super
+ end
+ EOT
+ end
end
protected

0 comments on commit 984d031

Please sign in to comment.