What happens if you try to access a key that doesn’t exist, though?

In many languages, you’ll get an error of some kind. Not so in Ruby: you’ll instead get the special value nil.

Along with false, nil is one of two non-true values in Ruby. (Every other object is regarded as “truthy,” meaning that if you were to type if 2 or if "bacon", the code in that if statement would be run.)

It’s important to realize that false and nil are not the same thing: false means “not true,” while nil is Ruby’s way of saying “nothing at all.”



Go ahead and try to access a key in creatures that doesn’t exist.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?