Shame on me poorr newbie " unexpected kend"

Hi,

I am trying to learn ruby through a udev utility coding.
I usually manage to debug on my own but in this case i dont understand
what is wrong…

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
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 ++
end
end
end
end

I get an unexpected kend at the end following the else…
I have one function, two while and one if - else, which mean four “end”
I tried to end the if before the else and to not end the else (because
of one line only) with no success.

Shamefull but I come for help.

Regards

Alexmic

On Apr 12, 2006, at 12:35 PM, alex mic wrote:

quest=“u”
found=1
@procdata = str
else
store ++

That’s not a valid Ruby statement. Try:

store += 1

  end
end

end
end

Hope that helps.

James Edward G. II

On 4/12/06, alex mic [email protected] wrote:

quest=“u”
@procdata = str
else
store ++

Ruby doesn’t support ++. I don’t know if that’s the only problem
though.

Hi,

Am Donnerstag, 13. Apr 2006, 02:42:39 +0900 schrieb James Edward G.
II:

That’s not a valid Ruby statement. Try:

store += 1

Further you probably want to increment `store’ at the end of
the outer loop.

Ruby is a good opportunity to write readable code. Do
yourself a favour and take it.

Bertram

Hi –

On Thu, 13 Apr 2006, alex mic wrote:

quest=“u”
while found!=1
io = IO.popen(“cat /proc/scsi/usb-storage/#{store}”, “r+”)
io.close_write
str = io.read
while quest!=“y” or quest!=“n”

See the other answers for the ++ and possibly other things – but note
also that this while will execute forever. Every string is either
not “y” or not “n” :slight_smile:

David


David A. Black ([email protected])
Ruby Power and Light, LLC (http://www.rubypowerandlight.com)

“Ruby for Rails” coming in PDF April 15, and in paper May 5!

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

while !(quest=="y" or quest=="n")
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

First thank you all for your fast answers.

james gray wrote:

That’s not a valid Ruby statement. Try:

store += 1
:slight_smile: Ex-con (java) habits are hard to loose
It fixed the error.

unknown wrote:

Hi –

On Thu, 13 Apr 2006, alex mic wrote:

quest=“u”
while found!=1
io = IO.popen(“cat /proc/scsi/usb-storage/#{store}”, “r+”)
io.close_write
str = io.read
while quest!=“y” or quest!=“n”

The loop is indeed infinite, i changed for
while !(quest==“y” or quest==“n”)

Here is the final method :slight_smile:

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

thanks again

Regards

Alexmic

Well obviously when I wrote “final method” I meant “possibly working
method yet very dirty one”.

Daniel H. wrote:

Don’t use numbers as a substitute for booleans.
Yes sir!
Just to mention that I haven’t coded for years and that TIMTOWTDI is a
friend I tend to rely on too much.

Also, why are you

calling IO.popen? File.read would work fine.
Of course. Well codind on a XP for linux is not always the best way to
proceed… Please pitty my condition, as having access to the files is
sometimes helpfull.

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

Well, this is more clean not to mention lines saving (I bet you gessed
this was not the only question of my piece of software) and reader
friendly.

Your help is greatly appriciated, so thanks again.

Alex.