Why does calling a method “ask” failed with undefined variable or method
File.open(‘lab_log.csv’, “a”) do |f|
$number = STDIN.gets.chomp
print "You selected "
puts list[+$number.to_i]
if $number.to_i.between?(0, 99)
puts “Who are you?”
#puts prompt
$user = STDIN.gets.chomp
ask
end
end
def ask
if $status == “lock”
puts “How many days do you want to #{$status} it for?”
$duration = STDIN.gets
today = DateTime.parse(Time.now.to_s)
# for month totalduration = (today>>1).strftime("%m/%d/%Y %H:%M")
totalduration = (today+$duration.to_i).strftime("%m/%d/%Y %H:%M")
elsif $status == “unlock”
print "Thank you! The "
print list[+$number.to_i]
print " is unlocked on "
print DateTime.now.strftime('%c')
f.print "Thank you! The "
f.print list[+$number.to_i]
f.print " is unlocked on "
f.print DateTime.now.strftime('%c')
elsif
$user.nil? or $user.empty?
puts “Nothing to input.”
else
puts "Your option is either 'lock' or 'unlock.' Wrong option was
entered. Exiting! \n"
return status
end
end # ask