Danyon Satterlee Danyon Satterlee - 6 months ago 13
Ruby Question

Ruby Beginner- unexpected end-of-input, expecting keyword_end

I am SUPER new to ruby, and I am trying to following instructions on how to build a rectangle. I am following along as carefully as possible, I triple checked I typed it correctly. I even retyped it. The problem seems to be in the end. My terminal keeps giving me the error: shapes.rb:25: syntax error, unexpected end-of-input, expecting keyword_end

Can anyone help me? I think it might be an issue with the 1.upto, but i'm not sure. Thank you so much!!

puts "Welcome to Shapes"
print "How big do you want your shape? "
shape_size = gets
shape_size = shape_size.chomp
print "Outside letter: "
outside_letter = gets
outside_letter = outside_letter.chomp
print " Inside Letter: "
inside_letter = gets
inside_letter = inside_letter.chomp
puts "About to draw a shape #{shape_size} big"
puts "using #{outside_letter} for the edge"
puts "and #{inside_letter} for the inside"
width = shape_size
height=shape_size
1.upto(height) do |row|
if row==1
puts outside_letter * width
elsif row==height
puts outside_letter * width
else
middle= inside_letter * (width-2)
puts
"#{outside_letter}#{middle}#{outside_letter}"
end

Answer

You need one more end:

puts "Welcome to Shapes"
print "How big do you want your shape? "
shape_size = gets
shape_size = shape_size.chomp
print "Outside letter: "
outside_letter = gets
outside_letter = outside_letter.chomp
print " Inside Letter: "
inside_letter = gets
inside_letter = inside_letter.chomp
puts "About to draw a shape #{shape_size} big"
puts "using #{outside_letter} for the edge"
puts "and #{inside_letter} for the inside"
width = shape_size
height=shape_size
1.upto(height) do |row|
  if row==1
    puts outside_letter * width
  elsif row==height
    puts outside_letter * width
  else
    middle= inside_letter * (width-2)
    puts
    "#{outside_letter}#{middle}#{outside_letter}"
  end
end # <--- here

Since you are learning here, I felt compelled to add more detail:

When you have a block, such as the 1.upto(height) do |row| in your code, that will always require an end, as it is a block (think of it like a unit of code). Within that block, you are executing the code for each item within the enumerable (ex. array). In this case, your enumerable is an array of each whole number between 1 and the value of height:

2.3.0 :005 > 1.upto(4) do |number|
2.3.0 :006 >     puts "The number is: #{number}"
2.3.0 :007?>   end
The number is: 1
The number is: 2
The number is: 3
The number is: 4