Skip to content
  • Jeremy Evans's avatar
    58325daa
    Make String methods return String instances when called on a subclass instance · 58325daa
    Jeremy Evans authored
    This modifies the following String methods to return String instances
    instead of subclass instances:
    
    * String#*
    * String#capitalize
    * String#center
    * String#chomp
    * String#chop
    * String#delete
    * String#delete_prefix
    * String#delete_suffix
    * String#downcase
    * String#dump
    * String#each/#each_line
    * String#gsub
    * String#ljust
    * String#lstrip
    * String#partition
    * String#reverse
    * String#rjust
    * String#rpartition
    * String#rstrip
    * String#scrub
    * String#slice!
    * String#slice/#[]
    * String#split
    * String#squeeze
    * String#strip
    * String#sub
    * String#succ/#next
    * String#swapcase
    * String#tr
    * String#tr_s
    * String#upcase
    
    This also fixes a bug in String#swapcase where it would return the
    receiver instead of a copy of the receiver if the receiver was the
    empty string.
    
    Some string methods were left to return subclass instances:
    
    * String#+@
    * String#-@
    
    Both of these methods will return the receiver (subclass instance)
    in some cases, so it is best to keep the returned class consistent.
    
    Fixes [#10845]
    58325daa
    Make String methods return String instances when called on a subclass instance
    Jeremy Evans authored
    This modifies the following String methods to return String instances
    instead of subclass instances:
    
    * String#*
    * String#capitalize
    * String#center
    * String#chomp
    * String#chop
    * String#delete
    * String#delete_prefix
    * String#delete_suffix
    * String#downcase
    * String#dump
    * String#each/#each_line
    * String#gsub
    * String#ljust
    * String#lstrip
    * String#partition
    * String#reverse
    * String#rjust
    * String#rpartition
    * String#rstrip
    * String#scrub
    * String#slice!
    * String#slice/#[]
    * String#split
    * String#squeeze
    * String#strip
    * String#sub
    * String#succ/#next
    * String#swapcase
    * String#tr
    * String#tr_s
    * String#upcase
    
    This also fixes a bug in String#swapcase where it would return the
    receiver instead of a copy of the receiver if the receiver was the
    empty string.
    
    Some string methods were left to return subclass instances:
    
    * String#+@
    * String#-@
    
    Both of these methods will return the receiver (subclass instance)
    in some cases, so it is best to keep the returned class consistent.
    
    Fixes [#10845]
Loading