Permalink
Browse files

Merge pull request #10600 from aditya-kapoor/code_refactor

Removed Class Eval and used define_method instead for the SafeBuffer
  • Loading branch information...
2 parents f93da57 + 426f42c commit 8ce3c1e5dde9fb180813e4d89324db03da110b13 @rafaelfranca rafaelfranca committed May 14, 2013
Showing with 9 additions and 11 deletions.
  1. +9 −11 activesupport/lib/active_support/core_ext/string/output_safety.rb
@@ -171,17 +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
+ if String.new.respond_to?(unsafe_method)
+ define_method(unsafe_method) do |*args, &block|
+ to_str.send(unsafe_method, *args, &block)
+ end
+
+ define_method("#{unsafe_method}!") do |*args|
+ @html_safe = false
+ super(*args)
+ end
end
end
end

0 comments on commit 8ce3c1e

Please sign in to comment.