0
Hello.
I’m an intermediate student in python, and recently I started studying Ruby, but like all new language, there are some small difficulties.
My question is: Where is the error in this? I used the function has_key?()
outside the class, and it worked perfectly, but within the class, from the following error:
`FuncLogin': undefined method `has_key?' for nil:NilClass (NoMethodError)
I am doing a simple program of login and account creation, but is giving this error. Follow the full code:
class User
attr_accessor :login, :password
@contas = {"admin" => "pass"}
def initialize(login, password)
@login = login
@password = password
end
def FuncLogin
if @contas.has_key?(@login)
if contas[@login] == @password
return "Logado"
else
puts "Senha incorreta."
end
else
return "Login inexistente."
end
end
end