Okay, I am a super SUPER noob, and I need help getting this right. I
want my code to keep asking users to enter the correct gender, but it
isn’t working… Down below you can see a very messy code, any help?
class GenderError < Exception
end
class Person
def gendercheck(x)
if (x.upcase != ‘FEMALE’) && (x.upcase != ‘MALE’)
raise GenderError
else
puts “You are a #{x}”
end
end
def initialize(gender)
@condition = false
@gender = gender
self.gendercheck(@gender)
rescue GenderError
puts “You put the wrong thing as a gender :: #{@gender}”
self.redo(@gender)
end
def redo(y)
@y = y
@y = gets()
if (@y.upcase != ‘FEMALE’) && (@y.upcase != ‘MALE’)
raise GenderError
else
@condition = true
self.gendercheck(@y)
end
rescue GenderError
if @condition == false
puts “Wrong Input again:: #{@y}”
self.redo(@y)
else
puts “You are a #{@y}”
end
end
attr_accessor :gender
end