Forum: Ruby Ruby 1.9 doesn't hace String#any?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0f1f17ba297242e9d3c86d4cc0a6ea85?d=identicon&s=25 Iñaki Baz Castillo (Guest)
on 2009-02-27 00:30
(Received via mailing list)
Hi, I'm trying:
  ruby 1.9.0 (2007-08-30 patchlevel 0) [i486-linux]
in Ubuntu.

I've realized that there is no method String#any?
Why? maybe it exists in a more recent version of 1.9?
Which would be the replacement method if not?

Thanks.
0f1f17ba297242e9d3c86d4cc0a6ea85?d=identicon&s=25 Iñaki Baz Castillo (Guest)
on 2009-02-27 00:35
(Received via mailing list)
El Viernes, 27 de Febrero de 2009, Iñaki Baz Castillo escribió:
> Hi, I'm trying:
>   ruby 1.9.0 (2007-08-30 patchlevel 0) [i486-linux]
> in Ubuntu.
>
> I've realized that there is no method String#any?
> Why? maybe it exists in a more recent version of 1.9?
> Which would be the replacement method if not?

Ok I've found that in Ruby 1.9 String is no more an Enumerable (and
"any?" is
defined in Enumerable module).
31e038e4e9330f6c75ccfd1fca8010ee?d=identicon&s=25 Gregory Brown (Guest)
on 2009-02-27 02:34
(Received via mailing list)
On Thu, Feb 26, 2009 at 6:33 PM, Iñaki Baz Castillo <ibc@aliax.net> wrote:
> El Viernes, 27 de Febrero de 2009, Iñaki Baz Castillo escribió:
>> Hi, I'm trying:
>>   ruby 1.9.0 (2007-08-30 patchlevel 0) [i486-linux]
>> in Ubuntu.
>>
>> I've realized that there is no method String#any?
>> Why? maybe it exists in a more recent version of 1.9?
>> Which would be the replacement method if not?
>
> Ok I've found that in Ruby 1.9 String is no more an Enumerable (and "any?" is
> defined in Enumerable module).

Right, so you just need to be specific about what you want to enumerate
over:

>> "foo\nbar".lines.any? { |e| e == "bar" }
=> true
>> "foo\nbar".chars.any? { |e| e == "b" }
=> true
>> "foo\nbar".bytes.any? { |e| e == 97 }
=> true
>> 97.chr
=> "a"


-greg
This topic is locked and can not be replied to.