Dir.foreach not with patterns?

K

Kurt V. Hindenburg

--Boundary-02=_GKgY/p64avOG7gO
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Content-Description: signed data
Content-Disposition: inline

Why does the third one not work as expected? It appears that=20
Dir.foreach will not work with patterns...

#!/usr/bin/ruby

s =3D "/etc/host*"

#1
l =3D Dir=20
p l

#2
Dir.foreach("/etc") { |d| p d }

#3
Dir.foreach(s) { |d| p d }

#4
# This is wasteful
l =3D Dir
l.each { |f| p f }

=2D-=20
^^^ Kurt

There is no good nor evil, just power.

--Boundary-02=_GKgY/p64avOG7gO
Content-Type: application/pgp-signature
Content-Description: signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQA/YgKG0cAvx3ELfKARAt8dAJ4wrTeNfjRnQZ9XrserhejBSuNGKACggWAk
WAnLflpyjLYvLKOZfQH4fcQ=
=Fd1o
-----END PGP SIGNATURE-----

--Boundary-02=_GKgY/p64avOG7gO--
 
N

nobu.nokada

Hi,

At Sat, 13 Sep 2003 02:28:02 +0900,
Kurt said:
Why does the third one not work as expected? It appears that
Dir.foreach will not work with patterns...

Use Dir.glob.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top