From: RLMuller Date: 2003-09-14T17:34:41+09:00 Subject: Does String#scan(/(..)(..)/) produce an array of arrays? This is a multi-part message in MIME format. ------=_NextPart_000_002A_01C37A79.49BBECF0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable Hi All, "Programming Ruby" says the following for String#scan at = http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_c_string.html#Strin= g.scan: a =3D "cruel world"=20 ... a.scan(/(..)(..)/) =BB [["cr", "ue"], ["l ", "wo"]] I wrote the following to test whether scan actually produced an array or = arrays: a =3D "cruel world"=20 ar =3D a.scan(/(..)(..)/) puts "Type of ar =3D %s of size %d" % [ar.class, ar.size] ix=3D0 ar.each {|x| puts "Type of ar[#{ix}] is %s" % [ix, ar[ix].class]; = ix+=3D1} That resulted in: Type of ar =3D Array of size 2 Type of ar[0] is 0 Type of ar[1] is 1 So it seem like we don't have an array of arrays. So what do we have? = Or am I all wet? Regards, Richard A programmer is a device for turning coffee into code. Jeff Prosise (with an assist from Paul Erdos) ------=_NextPart_000_002A_01C37A79.49BBECF0 Content-Type: text/html; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable
Hi All,
 
"Programming Ruby" says the following for = String#scan at http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_c_s= tring.html#String.scan:
 

a =3D "cruel world"=20

...

a.scan(/(..)(..)/) = =BB  = [["cr", "ue"], ["l ", "wo"]]

 

I wrote the = following to=20 test whether scan actually produced an array or = arrays:

 

a =3D "cruel = world"
ar =3D=20 a.scan(/(..)(..)/)
puts "Type of ar =3D %s of size %d" % [ar.class,=20 ar.size]
ix=3D0
ar.each {|x| puts "Type of ar[#{ix}] is %s" % [ix, = ar[ix].class]; ix+=3D1}

That resulted=20 in:

 

Type of ar=20 =3D Array of size 2
Type of ar[0] is 0
Type of ar[1] is=20 1

 

So it seem like we = don't=20 have an array of arrays.  So what do we have? Or am I all=20 wet?

 

Regards,
Richard
 
A programmer is a device for turning coffee into = code.
Jeff=20 Prosise (with an assist from Paul Erdos)
------=_NextPart_000_002A_01C37A79.49BBECF0--