Matthew Farmer Matthew Farmer - 3 months ago 25
Ruby Question

Windows Git uninitialized constant (NameError)

I'm using Ruby and getting this error. I am in Windows 10 using Git.

This is my code:

print "What's your name? "
name = gets.chomp
print "How old are you? "
age = gets.chomp
puts = "Your name is #{Matthew Farmer}, and your age is #{age}"


I can get it to ask both my name and age, but it keeps coming back as
gets.rb:7:in '<main>': uninitialized constant Farmer (NameError)
.

Answer

You didn't interpolate the name local variable, and you are assigning the value of a string to puts:

print "What's your name? "
name = gets.chomp
print "How old are you? "
age = gets.chomp
puts "Your name is #{name}, and your age is #{age}" # remove = ; change Matthew Farmer to name
Comments