Lesson 1 of 8 · 6 min

Hello, Ruby

Ruby was designed to make programmers happy: code reads almost like English, and there is usually a neat way to say what you mean. It powers Ruby on Rails, used by GitHub, Shopify and many startups.

puts "Good morning!"
puts 2 + 3

puts ("put string") prints a value followed by a new line. print does the same without the new line.

Variables

No keyword is needed: just a name, = and a value.

city = "Mutare"
population = 224_000      # underscores make big numbers readable
population += 1_000

String interpolation

Inside double quotes, #{...} puts any value or expression into the text:

puts "#{city} has #{population} people"
puts "Next year: #{population * 1.02}"

Single-quoted strings ('...') are taken literally, with no interpolation.

Ruby runs here in your browser. The first run downloads Ruby itself (about 16 MB), so it takes a little while; after that it is quick.

Your task

  1. Print Hello, Ruby!.
  2. Create name with "Chipo" and age with 24.
  3. Print Chipo is 24 years old using interpolation.
main.rb
# Your Ruby code here

Ruby 3.4 runs right here in your browser. The first run downloads about 16 MB; after that it is instant.

Discussion

Stuck? Ask here. Be kind, and share hints rather than full answers.

Loading the discussion…