[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby 1.9 doesn't hace String#any?

Iñaki Baz Castillo

2/26/2009 11:29:00 PM

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.

=2D-=20
I=C3=B1aki Baz Castillo

2 Answers

Iñaki Baz Castillo

2/26/2009 11:34:00 PM

0

El Viernes, 27 de Febrero de 2009, I=C3=B1aki Baz Castillo escribi=C3=B3:
> 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=20
defined in Enumerable module).

=2D-=20
I=C3=B1aki Baz Castillo

Gregory Brown

2/27/2009 1:27:00 AM

0

On Thu, Feb 26, 2009 at 6:33 PM, I=F1aki Baz Castillo <ibc@aliax.net> wrote=
:
> El Viernes, 27 de Febrero de 2009, I=F1aki Baz Castillo escribi=F3:
>> Hi, I'm trying:
>> =A0 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 ove=
r:

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


-greg

--=20
Technical Blaag at: http://blog.majesticseacr...
Non-tech stuff at: http://metametta.bl...
"Ruby Best Practices" Book now in O'Reilly Roughcuts:
http://rubybestpra...