I am trying to get something where if someone enters in a string, it verifies it and runs another function. My problem is that it ends the program instead of running the other function. Here is my code:
puts "redirecting to login"
def login()
puts ""
print "Username: "
username = gets.chomp
checkusername()
end
def password()
print "Password: "
passwordconf = gets.chomp
checkpassword()
end
def success()
puts "You're logged in!"
loop { sleep 10 }
end
def checkusername()
if username == name
password()
else
login()
end
end
def checkpassword()
if passwordconf == password
success()
else
login()
end
end
login()
loop { sleep 10 }
When login is running, and I type the gets for the string I am trying to check, when I press enter for the checkusername to run, the program ends, even if it is correct.
The login function runs the checkusername function once I type in a string, and hit enter. My problem is that once that happens, the program terminates, instead of either redirecting back to the login function or the password function. I am trying to figure out how that will not happen.
Error output:
Traceback (most recent call last):
2: from blank.rb:41:in `<main>'
1: from blank.rb:16:in `login'
blank.rb:28:in `checkusername': undefined local variable or method `username' for main:Object (NameError)
I am quite a beginner at Ruby, and I have spent quite a bit of time getting this to work, but I am unable. Thanks!