0

coming from PHP so I'm sorry if the question is too easy for yall :/

My code looks like

animals = [
  "horse" => "Caballo",
  "Dog" => "Perro",
  "Cat" => "Gato",
  "Hawk" => "Halcon"
]


puts animals[2]

but is not working it aint printing anything on the terminal ... I don't know if this is the right way to do it in ruby or not :/

what I'm trying to do is to reference individual values for example:

Horse in spanish is animals['horse']

1 Answer 1

2

Use {} to define a hash then:

animals = {
  "horse" => "Caballo",
  "Dog"   => "Perro",
  "Cat"   => "Gato",
  "Hawk"  => "Halcon"
}

puts animals["horse"]
#Caballo
Sign up to request clarification or add additional context in comments.

1 Comment

omg :( I did spend like 40 minutes trying to find the solution. Thank you :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.