Shame on me poorr newbie " unexpected kend"

and you can simplify this even more:

···

-----Original Message-----
From: Daniel Harple [mailto:dharple@generalconsumption.org]
Sent: Thursday, April 13, 2006 4:06 PM
To: ruby-talk ML
Subject: Re: Shame on me poorr newbie " unexpected kend"

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

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

def find_device
   puts "We are now trying to find the device"
   Dir["/proc/scsi/usb-storage/*"].each do |usb_dev|
     usb = File.read(usb_dev)
     return usb if ask("Found in #{usb_dev}: #{usb}. Is this your
device?")
   end && nil
end

procdata = find_device
------------------------------------------------------------------------
-

cheers

Simon

p.s.: I have no /proc/scsi/usb-storage (win2000) so this is untested.

Tested and am glad to get the following:
$ ruby find_usbdev.rb
We are now trying to find the device
Found in /proc/scsi/usb-storage/3: Host scsi3: usb-storage
       Vendor: SanDisk Corporation
      Product: Cruzer Mini
Serial Number: 2004351462080892ebd0
     Protocol: Transparent SCSI
    Transport: Bulk
       Quirks:
. Is this your
device? [y/n]: y

Prasad

···

On 4/13/06, Kroeger, Simon (ext) <simon.kroeger.ext@siemens.com> wrote:

> -----Original Message-----
> From: Daniel Harple [mailto:dharple@generalconsumption.org]
> Sent: Thursday, April 13, 2006 4:06 PM
> To: ruby-talk ML
> Subject: Re: Shame on me poorr newbie " unexpected kend"
>
> 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

and you can simplify this even more:
------------------------------------------------------------------------
-
def ask(msg)
   loop do
     print "#{msg} [y/n]: "
     response = gets().strip
     return true if response == 'y'
     return false if response == 'n'
     puts "Invalid response. Please enter y or n"
   end
end

def find_device
   puts "We are now trying to find the device"
   Dir["/proc/scsi/usb-storage/*"].each do |usb_dev|
     usb = File.read(usb_dev)
     return usb if ask("Found in #{usb_dev}: #{usb}. Is this your
device?")
   end && nil
end

procdata = find_device
------------------------------------------------------------------------
-

cheers

Simon

p.s.: I have no /proc/scsi/usb-storage (win2000) so this is untested.