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
- Print
Hello, Ruby!. - Create
namewith"Chipo"andagewith24. - Print
Chipo is 24 years oldusing interpolation.