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.

Chars class doesn't proxy "include?"

#140

The docs state that "Chars objects are perfectly interchangeable with String objects as long as no explicit class checks are made."

However at least one String method does not work on Chars objects:

>>"foo".chars.include?("f")

ArgumentError: wrong number of arguments (2 for 1)

from /Library/Ruby/Gems/1.8/gems/activesupport-1.4.4/lib/active_support/multibyte/chars.rb:81:in `include?'

from /Library/Ruby/Gems/1.8/gems/activesupport-1.4.4/lib/active_support/multibyte/chars.rb:81:in `send'

Reported by jdwyah · May 7th, 2008 @ 11:17 PM

State: duplicate
Milestone: none
Assigned to: Pratik Pratik
Importance: none

Activity

  1. Xavier Noria
    Xavier Noria

    Problem is

    >> "foo".chars.handler.respond_to?("include?")
    => true
    >> "foo".chars.handler
    => ActiveSupport::Multibyte::Handlers::UTF8Handler
    

    that is a Class object, which responds to "include?" because of Module#include?. That method expects an argument and it is being passes the proxied string and the argument itself.

    May 7th, 2008 @ 11:47 PM

  2. Xavier Noria
    Xavier Noria

    Let me rephrase the comment above.

    The proxy asks first the handler if it responds to the method, if it does not sends it to the proxied string.

    Since the handler responds to "include?" it gets called on it, but that method is Module#include?. So indeed there's a mismatch in the interface, and additionallly that's the explanation for the way it breaks.

    May 7th, 2008 @ 11:58 PM

  3. jdwyah
    jdwyah

    Yep, I agree that this is the problem. What do you think, is it appropriate to just add an include? method to Chars (or UTF8Handler)? or is there a cleaner fix?

    May 8th, 2008 @ 01:44 AM

  4. Yaroslav Markin
    Yaroslav Markin

    I think #include? should be defined for Multibyte..

    May 11th, 2008 @ 03:56 PM

  5. Manfred Stienstra
    Manfred Stienstra

    The correct fix would be to add an include? method to the handler.

    May 11th, 2008 @ 01:29 PM

  6. Craig Davey
  7. Craig Davey
    Craig Davey
    • Tag set to 2.0-stable, activesupport, bug

    This patch adds an include? method to ActiveSupport::Multibyte::Handlers::UTF8Handler so that string.chars.include? acts the same as string.include?

    July 13th, 2008 @ 02:02 AM

  8. Manfred Stienstra
    Manfred Stienstra
    • Tag changed from 2.0-stable, activesupport, bug to 2.0-stable, activesupport, bug

    This seems to be fixed, can someone close this ticket?

    October 3rd, 2008 @ 01:00 PM

  9. Yaroslav Markin
    Yaroslav Markin
    • Tag changed from 2.0-stable, activesupport, bug to 2.0-stable, activesupport, bug
    • Assigned user set to Pratik

    November 25th, 2008 @ 04:44 PM

  10. Pratik
  11. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • Tag cleared.

    Automatic cleanup of spam.

    November 8th, 2010 @ 08:26 AM

  12. bingbing