ruby · level 1 · unit 2 · lesson 3
- meet it
- guess first
- your turn
- fix it
- nailed it
Tap a green word if you get lost.
meet it
A good name tells you what is in the box.
Ruby has rules for names. Use small letters, digits and underscores. No spaces, and never start with a digit. Start with a small letter too, because a capital at the front means something else in Ruby.
When a name needs two words, join them with an underscore, like favourite_colour. This style is called , because the words lie long and low, like a snake.
Ruby is : capital and small letters count as different, so score and Score are not the same name. Pick names that say what is inside, like pet_name, not x.
favourite_colour = "green"
puts favourite_colour A name like x works, but in a week you will not remember what is in it.
guess first
One capital letter. What happens?
Guess before you run it. Wrong guesses are how you learn, and nothing is marked.
pet_name = "Rex"
puts Pet_name
your turn
Your turn. Name the box yourself.
Think of a snake_case name for a box holding your dream holiday place, like dream_trip. Type the same name in both blanks, then press run.
fix it
This name breaks a rule. Can you fix it?
- Ruby is confused by line 1. Look at the gap in the middle of the name.
- Names cannot have spaces. Ruby reads best and friend as two separate words.
- Use snake_case: change both to best_friend, then press run.
nailed it
you can name things like a pro. :D
- Use small letters, digits and underscores. No spaces.
- Join words with underscores: that is snake_case.
- Ruby is case-sensitive, so
Scoreis notscore.
new words in your collection
- snake_case
- case-sensitive
This lesson isn’t saved. A free account remembers every lesson you finish.