how to write in an array inside a block?

Z

Zathras Draal

Hello,

i want to write all files from my local directory in an array.

Something like (not working):

d = Dir.new("/Volumes/System/")
d.each {|x| file_list.push(x) }

How can i push single filenames through d.each into an array?

Thanks a lot in advance!
 
A

Aldric Giacomoni

Chris said:
If file_list did not exist before the block,
it will not exist after the block exits. Declarations inside blocks
are scoped to the block

I think if you look at the docs for Dir you'll find a method that will
give you the list of files withtout the need of the block
cheers

Indeed.

irb> file_list = 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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top