Skip to content

Commit

Permalink
Merge pull request #3229 from amatsuda/string_prepend
Browse files Browse the repository at this point in the history
ruby193: String#prepend
  • Loading branch information
josevalim committed Oct 5, 2011
2 parents 4cea4ee + 87eab59 commit ae4febd
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions activesupport/lib/active_support/core_ext/string/output_safety.rb
Expand Up @@ -75,7 +75,7 @@ def html_safe?


module ActiveSupport #:nodoc: module ActiveSupport #:nodoc:
class SafeBuffer < String class SafeBuffer < String
UNSAFE_STRING_METHODS = ["capitalize", "chomp", "chop", "delete", "downcase", "gsub", "lstrip", "next", "reverse", "rstrip", "slice", "squeeze", "strip", "sub", "succ", "swapcase", "tr", "tr_s", "upcase"].freeze UNSAFE_STRING_METHODS = ["capitalize", "chomp", "chop", "delete", "downcase", "gsub", "lstrip", "next", "reverse", "rstrip", "slice", "squeeze", "strip", "sub", "succ", "swapcase", "tr", "tr_s", "upcase", "prepend"].freeze


alias_method :original_concat, :concat alias_method :original_concat, :concat
private :original_concat private :original_concat
Expand Down Expand Up @@ -142,16 +142,18 @@ def to_yaml(*args)
end end


UNSAFE_STRING_METHODS.each do |unsafe_method| UNSAFE_STRING_METHODS.each do |unsafe_method|
class_eval <<-EOT, __FILE__, __LINE__ + 1 if 'String'.respond_to?(unsafe_method)
def #{unsafe_method}(*args, &block) # def capitalize(*args, &block) class_eval <<-EOT, __FILE__, __LINE__ + 1
to_str.#{unsafe_method}(*args, &block) # to_str.capitalize(*args, &block) def #{unsafe_method}(*args, &block) # def capitalize(*args, &block)
end # end to_str.#{unsafe_method}(*args, &block) # to_str.capitalize(*args, &block)
end # end
def #{unsafe_method}!(*args) # def capitalize!(*args)
@dirty = true # @dirty = true def #{unsafe_method}!(*args) # def capitalize!(*args)
super # super @dirty = true # @dirty = true
end # end super # super
EOT end # end
EOT
end
end end


protected protected
Expand Down

0 comments on commit ae4febd

Please sign in to comment.