Permalink
Browse files

Removed Class Eval and used define_method instead for the SafeBuffer

  • Loading branch information...
1 parent 37ca5b0 commit 069ea45c5d4b0215d4aa3ce57316cfbc8db5ba9e @aditya-kapoor aditya-kapoor committed May 13, 2013
Showing with 9 additions and 12 deletions.
  1. +9 −12 activesupport/lib/active_support/core_ext/string/output_safety.rb
@@ -171,18 +171,15 @@ def encode_with(coder)
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

0 comments on commit 069ea45

Please sign in to comment.