This project is archived and is in readonly mode.
Chars class doesn't proxy "include?"
Reported by jdwyah | May 7th, 2008 @ 11:17 PM
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'
Comments and changes to this ticket
-
Xavier Noria May 7th, 2008 @ 11:47 PM
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.
-
Xavier Noria May 7th, 2008 @ 11:58 PM
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.
-
jdwyah May 8th, 2008 @ 01:44 AM
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?
-
Manfred Stienstra May 11th, 2008 @ 01:29 PM
The correct fix would be to add an include? method to the handler.
-
Craig Davey July 13th, 2008 @ 02:02 AM
- no changes were found...
-
Craig Davey July 13th, 2008 @ 02:02 AM
- 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?
-
Manfred Stienstra October 3rd, 2008 @ 01:00 PM
- Tag changed from 2.0-stable, activesupport, bug to 2.0-stable, activesupport, bug
This seems to be fixed, can someone close this ticket?
-
Yaroslav Markin November 25th, 2008 @ 04:44 PM
- Tag changed from 2.0-stable, activesupport, bug to 2.0-stable, activesupport, bug
- Assigned user set to Pratik
-
Pratik December 7th, 2008 @ 03:22 AM
- State changed from new to duplicate
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>