From 069ea45c5d4b0215d4aa3ce57316cfbc8db5ba9e Mon Sep 17 00:00:00 2001 From: aditya-kapoor Date: Tue, 14 May 2013 01:09:03 +0530 Subject: Removed Class Eval and used define_method instead for the SafeBuffer --- .../active_support/core_ext/string/output_safety.rb | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'activesupport/lib/active_support/core_ext/string') 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 dc033ed11b..c368e7f505 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -171,18 +171,15 @@ module ActiveSupport #:nodoc: end UNSAFE_STRING_METHODS.each do |unsafe_method| - 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) - @html_safe = false # @html_safe = false - super # super - end # end - EOT - end + if String.new.respond_to?(unsafe_method) + define_method(unsafe_method.to_sym) do |*args, &block| + to_str.send(unsafe_method, *args, &block) + end + define_method("#{unsafe_method}!".to_sym) do |*args| + @html_safe = false + super(*args) + end + end end end end -- cgit v1.2.3