From: Robert Klemme Date: 2007-11-13T23:23:00+09:00 Subject: Re: How do I exit from a block 2007/11/13, Jigar Gosar : > base_dir = "C:/pde" > > def list base_dir > d= Dir.new base_dir > d.each {|x| > return "asd" if x.eql? "." > return "asd" if x.eql? ".." > puts "Got #{x}" > full_name = base_dir+"/"+x > if(File.directory?(full_name)) > list full_name > end > } > end > > puts ( list base_dir) Why do you use "puts" here? As far as I can see you do the printing in #list. > The return inside the block in the "list" method actually return from > the "list" method itself. But i just wanted to exit the block. how does > one exit from a block in ruby? > > please advise. Not exactly the answer you were looking for, but... 15:21:46 /$ ruby -r find -e 'Find.find("/tmp") {|f| puts f}' /tmp /tmp/uscreens /tmp/uscreens/S-rklemme /tmp/4052 /tmp/4052/sshlog /tmp/4052/servicelog /tmp/4052/runlog /tmp/4052/keylog /tmp/.X11-unix /tmp/.X11-unix/X0 Cheers robert -- use.inject do |as, often| as.you_can - without end