Hello.
I'm an intermediate student in python, and recently I started studying Ruby, but like every new language, comes a few minor difficulties.
My question is: Where is the error in this? I used the has_key?()
function outside of the class, and it worked perfectly, but within the class, it gives the following error:
'FuncLogin': undefined method 'has_key?' for nil:NilClass (NoMethodError)
I'm doing a simple login and account creation program, but it's giving this error. Here is the complete 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