# Shame on me poorr newbie " unexpected kend"

**URL:** <https://www.ruby-forum.com/t/shame-on-me-poorr-newbie-unexpected-kend/57645>\
**Category:** Ruby\
**Created:** [April 12, 2006, 7:35pm UTC](https://www.ruby-forum.com/t/shame-on-me-poorr-newbie-unexpected-kend/57645 "2006-04-12T19:35:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexmic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@alexmic](https://www.ruby-forum.com/u/alexmic)\
**Post date:** [April 12, 2006, 7:35pm UTC](https://www.ruby-forum.com/t/shame-on-me-poorr-newbie-unexpected-kend/57645/1 "2006-04-12T19:35:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alexmic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@alexmic](https://www.ruby-forum.com/u/alexmic)\
**Post date:** [April 12, 2006, 7:43pm UTC](https://www.ruby-forum.com/t/shame-on-me-poorr-newbie-unexpected-kend/57645/2 "2006-04-12T19:43:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alexmic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@alexmic](https://www.ruby-forum.com/u/alexmic)\
**Post date:** [April 12, 2006, 7:49pm UTC](https://www.ruby-forum.com/t/shame-on-me-poorr-newbie-unexpected-kend/57645/3 "2006-04-12T19:49:32Z")

</div>

On 4/12/06, alex mic [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

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

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

---

<div class="post-metadata">

**Author:** ![alexmic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@alexmic](https://www.ruby-forum.com/u/alexmic)\
**Post date:** [April 12, 2006, 9:33pm UTC](https://www.ruby-forum.com/t/shame-on-me-poorr-newbie-unexpected-kend/57645/4 "2006-04-12T21:33:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alexmic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@alexmic](https://www.ruby-forum.com/u/alexmic)\
**Post date:** [April 13, 2006, 12:21am UTC](https://www.ruby-forum.com/t/shame-on-me-poorr-newbie-unexpected-kend/57645/5 "2006-04-13T00:21:56Z")

</div>

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” 🙂

David

–  
David A. Black (removed\_email\_address@domain.invalid)  
Ruby Power and Light, LLC ([http://www.rubypowerandlight.com](http://www.rubypowerandlight.com))

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

> **[Ruby for Rails](https://www.manning.com/books/ruby-for-rails?new=true&experiment=A)**
>
> NEWER EDITION AVAILABLE
> 
> The Well-Grounded Rubyist, Second Edition is now available. An eBook of the previous edition, The Well-Grounded Rubyist is included at no additional cost when you buy the revised edition! 
> 
> 
> Ruby for Rails helps Rails...

---

<div class="post-metadata">

**Author:** ![alexmic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@alexmic](https://www.ruby-forum.com/u/alexmic)\
**Post date:** [April 13, 2006, 4:08pm UTC](https://www.ruby-forum.com/t/shame-on-me-poorr-newbie-unexpected-kend/57645/6 "2006-04-13T16:08:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![alexmic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@alexmic](https://www.ruby-forum.com/u/alexmic)\
**Post date:** [April 13, 2006, 11:57am UTC](https://www.ruby-forum.com/t/shame-on-me-poorr-newbie-unexpected-kend/57645/7 "2006-04-13T11:57:22Z")

</div>

First thank you all for your fast answers.

james gray wrote:

> That’s not a valid Ruby statement. Try:
> 
> store += 1  
> 🙂 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 🙂

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

---

<div class="post-metadata">

**Author:** ![alexmic](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@alexmic](https://www.ruby-forum.com/u/alexmic)\
**Post date:** [April 13, 2006, 7:44pm UTC](https://www.ruby-forum.com/t/shame-on-me-poorr-newbie-unexpected-kend/57645/8 "2006-04-13T19:44:26Z")

</div>

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.
