On Apr 13, 2006, at 11:57 AM, alex mic wrote:

> def finddevice()
>   puts "We are now trying to find the device"
>   found=0
>   store=0
>   quest="u"
>   while found!=1
>     io = IO.popen("cat /proc/scsi/usb-storage/#{store}", "r+")
>     io.close_write
>     str = io.read
>     puts str
>     while !(quest=="y" or quest=="n")
>       puts "This is what is found on /proc/scsi/usb-storage/# 
> {store}. Is
> it your device [y/n]"
>       quest=gets.chop!.downcase
>       if quest=="y"
>       	found=1
>       	@procdata = str
>       else
>         store+=1
>       end
>     end
>   end
> end

Don't use numbers as a substitute for booleans. Also, why are you  
calling IO.popen? File.read would work fine.

def ask(msg)
   loop do
     print "#{msg} [y/n]: "
     response = gets().strip
     if response == "y"
       return true
     elsif response == "n"
       return false
     else
       puts "Invalid response. Please enter y or n"
     end
   end
end

def find_device
   puts "We are now trying to find the device"
   store = 0
   loops do
     usb_dev = "/proc/scsi/usb-storage/#{store}"
     usb = File.read(usb_dev)
     if ask("Found in #{usb_dev}: #{usb}. Is this your device?")
       @procdata = usb
       break
     else
       store += 1
     end
   end
end


-- Daniel