Genie.rb:20: syntax error, unexpected $end, expecting kEND

I get “genie.rb:20: syntax error, unexpected $end, expecting kEND” every
I try to run the above program. It’s just something I did for fun to
impress freinds/family. I’ve looked over it many times, trying to mess
with things a little to fix it, but nothing seems to work. I’m pretty
new to the whole programming scene (I actually started yesterday) so I
probably missed something really easy but it still baffels me. Help
would be greatly appreciated for anyone who would be kind enough to give
it.

Hi –

On Sun, 19 Jul 2009, Alec Williams wrote:

I get “genie.rb:20: syntax error, unexpected $end, expecting kEND” every
I try to run the above program. It’s just something I did for fun to
impress freinds/family. I’ve looked over it many times, trying to mess
with things a little to fix it, but nothing seems to work. I’m pretty
new to the whole programming scene (I actually started yesterday) so I
probably missed something really easy but it still baffels me. Help
would be greatly appreciated for anyone who would be kind enough to give
it.

Every if statement has to have an ‘end’. Right now you’ve got more
if’s than end’s. It’s because you’re using this:

else
if

(with no ‘end’ for the if) instead of:

elsif

They’re both OK, but if you use the first one, you’re starting a new
if and it has to have its own end.

Compare these two:

if x
puts “x is true”
elsif y
puts “y is true”
else
puts “Neither is true”
end

if x
puts “x is true”
else
if y
puts “y is true”
else
puts “Neither is true”
end
end

You’re doing something like the second, but without matching if/end.

David

On Sunday 19 July 2009, Alec Williams wrote:

|http://www.ruby-forum.com/attachment/3884/genie.rb
You are missing two end before the last one. By the way, if you want to
have
several “branches” in your if statement, you can use the elsif keyword
instead
of nested else/if. This would make your code shorter and much easier to
read
and debug. Here’s how it would look:

puts ‘You see a lamp on the floor of a dusty room. Do you pick it up and
rub it?’
lamp=gets.chomp

if lamp==‘No’
puts ‘You turn around, and walk out of the room, always to wonder
whether or not you should have rubbed it…’
elsif lamp==‘Yes’
puts ‘You walk up to the lamp and stroke it. Suddenly a genie bursts
out and says “You have released me from my eternal prison. I shall now
grant you one wish! State it in “I wish for (blank)” format
please. State it, and it shall be done.”’
wish=gets.chomp
if (wish== ‘I wish for world peace’ or wish== ‘I wish for the end of
world hunger’)
puts ‘That’s very thoughtful of you. It shall be done!’
elsif (wish== ‘I wish for the winning lottery ticket’ or wish== ‘I
wish for $1,000,000’)
puts ‘That is very selfish of you, but I must hold a promise. Your
wish shall be granted.’
else
puts ‘Your wish is my command.’
end
end
puts ‘You walk out of the dusty room, into the sunshine, awaiting a
changed life as a result of your recently granted wish.’

I hope this helps

Stefano

Send (or link) this whole galaxygetCSV.rb that somebody can help you
find the place where the “end” should be (and it’s not).

Abinoam Jr.

i need help on this piece of code, i am new to ruby programming, i just
applied Has_one and belongs To relationship between two models but i
encountered this error while while trying to load the program. i have
tried to rollback my migrations and to migratate them again without
success.

home/gbolahan/sites/spotvilla/app/models/clisting.rb:2: syntax error,
unexpected ‘:’, expecting kEND
has_one: category
^

Rails.root: /home/gbolahan/sites/spotvilla
Application Trace | Framework Trace | Full Trace

app/controllers/clistings_controller.rb:1

On 11/16/2011 04:53, gbolahan a. wrote:

home/gbolahan/sites/spotvilla/app/models/clisting.rb:2: syntax error,
unexpected ‘:’, expecting kEND
has_one: category
^

Replace the above with this:

has_one :category

Note the new location of the colon. The has_one thing is a method and
it takes a symbol as an argument. You can form a symbol by prefixing
some kinds of text with a colon, so :category is a symbol that is going
to be passed to the has_one method.

Take note that white space is important in Ruby as with many programming
languages, so make sure that you follow examples carefully. :slight_smile:

-Jeremy

galaxygetCSV.rb:46: syntax error, unexpected kEND, expecting $end

This was caused in one instance by failing to begin the method with
“def”.

-----Messaggio originale-----
Da: Jeremy B. [mailto:[email protected]]
Inviato: mercoled 16 novembre 2011 16:11
A: ruby-talk ML
Oggetto: Re: genie.rb:20: syntax error, unexpected $end, expecting kEND

On 11/16/2011 04:53, gbolahan a. wrote:

home/gbolahan/sites/spotvilla/app/models/clisting.rb:2: syntax error,
unexpected ‘:’, expecting kEND
has_one: category
^

Replace the above with this:

has_one :category

Note the new location of the colon. The has_one thing is a method and
it
takes a symbol as an argument. You can form a symbol by prefixing some
kinds of text with a colon, so :category is a symbol that is going to be
passed to the has_one method.

Take note that white space is important in Ruby as with many programming
languages, so make sure that you follow examples carefully. :slight_smile:

-Jeremy


Caselle da 1GB, trasmetti allegati fino a 3GB e in piu’ IMAP, POP3 e
SMTP autenticato? GRATIS solo con Email.it http://www.email.it/f

Sponsor:
Capodanno a Riccione, Pacchetto Relax: Mezza Pensione + bagno turco +
solarium + massaggio. Wifi e parcheggio gratis. 2 giorni euro 199 a
persona
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid978&d)-12