Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, coding guys,

As you saw in the title, Ruby is throwing me:

main.rb:59: syntax error, unexpected end-of-input, expecting `end'

and, this is my code:

main.rb
# Logging
puts "Hello, world!\n"

# Input getting & variables
puts "What is your name?"
a0 = gets.strip
puts "Hi, " + a0 + "!\n"

# Classes and their methods/functions
class Tyrunt
	def initialize(name)
		@name = name
	end

	def reewr
		puts "The Tyrunt #{@name} reewred a bit!"
		"Reewr"
	end

	def say(msg)
		puts "#{@name}: #{msg}"
	end

	def ask(q)
		puts "#{@name}: #{q}"
		gets.strip
	end

	def stick(place)
		puts "#{@name} is stuck in #{place}"
end

a1 = Tyrunt.new("Rix")
puts "*#{a1.reewr().downcase()}*"
a1.say("Ruby is cool!")
a2 = a1.ask("Righty? [y/n]").downcase()[0]
if a2 == "y"
	a1.say(":D")
elsif a2 == "n"
	a1.say("Come on! :'(")
end
puts "\n"

# Functions
def party(emoji)
	puts "#{emoji} Party! #{emoji}"
end

party("🎉")
puts "\n"

# Math
a1.stick("his homework")
a3 = a1.ask("1+2=?")
if a3 == "3" then
	a1.say("Oh, RIGHT!")
else
	a1.say("I don't know if it's true...")
end


And, in the end of this code, I see:

main.rb
end


of a if>else statement. Why does Ruby throw me this exception and is there a way to fix it?

What I have tried:

                              
Posted
Updated 12-May-22 1:04am
v2

1 solution

Oh, I just needed to add `end` in the `stick(place)` function!
 
Share this answer
 
Comments
CHill60 12-May-22 14:42pm    
Looks like you jumped a little too quickly into asking other people for help - it took you 5 minutes to find the solution to your own problem. There's a lesson there ...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900