Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

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

#1243

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="こんは">

Reported by George Ogata · October 21st, 2008 @ 01:07 AM

State: resolved
Milestone: 2.x
Assigned to: Pratik Pratik
Importance: none

Activity

  1. Manfred Stienstra
    Manfred Stienstra
    • Assigned user set to Manfred Stienstra

    December 30th, 2008 @ 12:24 PM

  2. Manfred Stienstra
    Manfred Stienstra

    Patch looks great, thanks. I've modified it slightly to put more information in the commit message.

    December 30th, 2008 @ 01:28 PM

  3. George Ogata
    George Ogata

    Cool, thanks. Does this mean it'll be merged in?

    There are a few other methods that differ from String. Specifically, some of those bang methods should return nil if no modification occurred. I can patch those too if this gets the green light.

    George.

    January 2nd, 2009 @ 02:31 PM

  4. Manfred Stienstra
    Manfred Stienstra

    Let's hope so (: Unfortunately I can't push to the main repository myself, but I will make sure someone commits it.

    I was thinking about getting the String specs from RubySpec and using those in the Multibyte tests to make sure it works as much like String as possible.

    January 2nd, 2009 @ 02:55 PM

  5. George Ogata
  6. Pratik
    Pratik
    • Assigned user changed from Manfred Stienstra to Pratik

    Hey Manfred,

    Is this ready to be committed ?

    Thanks.

    March 7th, 2009 @ 08:27 PM

  7. Manfred Stienstra
    Manfred Stienstra

    Yeah, you can commit it if you want.

    March 7th, 2009 @ 10:35 PM

  8. Repository
    Repository
    • State changed from new to resolved

    (from [74387884819e8b6e16c3f67388610b8d1192cb4d]) Make Chars#slice! behave more like String#slice! [#1243 state:resolved]

    • Chars#slice! now returns the slice instead of itself
    • Chars#slice! now removes the slice from itself

    Signed-off-by: Pratik Naik pratiknaik@gmail.com http://github.com/rails/rails/co...

    March 7th, 2009 @ 10:41 PM