0
@users = [
{id:"0", name:"Thomas One", email:"thomas@fake.nl", password:"adkdjaso"},
{id:"1", name:"James Five", email:"j4@fake.nl", password:"jdajdlae"},
{id:"3", name:"Gordon Four", email:"g4@fake.nl", password:"adsldsae"}
]

def getId
  puts "what is your email address?"
    @account = gets.chomp

  if @users.find |x| x[email:] == @account
    puts "Welcome #{@users[name:]}"
    break
  else 
    puts "your account does not exist try again!"
  end
end

how do i search through an array of hashes based of the users email and then print out his name ?

AbNadi
  • 69
  • 1
  • 10

1 Answers1

2

You can do something like this

@email = "thomas@fake.nl"
user = @users.find {|u| u[:email] == @email}
if user
  puts "Welcome #{user[:name]}"
else
  puts "Your account does not exist try again!"
end
user1875195
  • 968
  • 4
  • 8
  • 22