# Ruby 1.9 doesn't hace String#any?

**URL:** <https://www.ruby-forum.com/t/ruby-1-9-doesnt-hace-string-any/161508>\
**Category:** Ruby\
**Created:** [February 27, 2009, 12:30am UTC](https://www.ruby-forum.com/t/ruby-1-9-doesnt-hace-string-any/161508 "2009-02-27T00:30:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [February 27, 2009, 12:30am UTC](https://www.ruby-forum.com/t/ruby-1-9-doesnt-hace-string-any/161508/1 "2009-02-27T00:30:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [February 27, 2009, 12:35am UTC](https://www.ruby-forum.com/t/ruby-1-9-doesnt-hace-string-any/161508/2 "2009-02-27T00:35:06Z")

</div>

El Viernes, 27 de Febrero de 2009, IÃ±aki Baz C. 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).

---

<div class="post-metadata">

**Author:** ![ISSSSaki\_Baz\_C](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/51bf81/32.png) [@ISSSSaki\_Baz\_C](https://www.ruby-forum.com/u/ISSSSaki_Baz_C)\
**Post date:** [February 27, 2009, 2:34am UTC](https://www.ruby-forum.com/t/ruby-1-9-doesnt-hace-string-any/161508/3 "2009-02-27T02:34:09Z")

</div>

On Thu, Feb 26, 2009 at 6:33 PM, Iñaki Baz C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> El Viernes, 27 de Febrero de 2009, Iñaki Baz C. 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
