This project is archived and is in readonly mode.

#1243 ✓resolved
George Ogata

Make AS::Multibyte::Chars#slice! behave more like String#slice!

Reported by George Ogata | October 21st, 2008 @ 01:07 AM | in 2.x

Currently, doing a slice! on a Multibyte::Chars modifies the string to become equal to the return value:

>> s = 'こんにちは'.mb_chars
=> #<ActiveSupport::Multibyte::Chars:0x24c4ddc @wrapped_string="こんにちは">
>> s.slice!(2..3)
=> #<ActiveSupport::Multibyte::Chars:0x24c4ddc @wrapped_string="にち">
>> s
=> #<ActiveSupport::Multibyte::Chars:0x24c4ddc @wrapped_string="にち">

As opposed to String#slice!, which removes the slice from the string:

>> s = 'abcde'
=> "abcde"
>> s.slice!(2..3)
=> "cd"
>> s
=> "abe"

This patch does what's needed:

>> s = 'こんにちは'.mb_chars
=> #<ActiveSupport::Multibyte::Chars:0x24cc960 @wrapped_string="こんにちは">
>> s.slice!(2..3)
=> #<ActiveSupport::Multibyte::Chars:0x24caf84 @wrapped_string="にち">
>> s
=> #<ActiveSupport::Multibyte::Chars:0x24cc960 @wrapped_string="こんは">

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Referenced by

Pages