Strings hold text — and Ruby gives them a toolbox of methods plus the elegant #{...} interpolation trick.
1 Quotes make strings
Single or double quotes both work — but only "..." interpolates.
2 Interpolation #{...}
Drops any Ruby expression straight into the text, results included.
3 Methods on tap
upcase, length, reverse and friends return brand-new strings.
4 Strings do math too
+ glues two strings together; * repeats one: "ha" * 3 is "hahaha".
Working with words
Quotes make strings1Single or double quotes both work — but only "..." interpolates. Interpolation #{...}2Drops any Ruby expression straight into the text, results included.
Methods on tap3upcase, length, reverse and friends return brand-new strings. Strings do math too4+ glues two strings together; * repeats one: "ha" * 3 is "hahaha".
4 building blocks make up Working with words
One little string gets copied, counted and reversed — watch which methods change it and which do not.
mainname points to the lowercase String "ada".
Console
output appears as the program runs…
From the # character to a finished string — what Ruby does the moment it builds "Hi, #{name}!".
Click a method, then click what it does to lock the pair.
6 conceptsTap a card to expand ?upcase / downcasedrops into place
?lengthdrops into place
?reversedrops into place
?#{name}drops into place
?stripdrops into place
?include?("a")drops into place
Double quotes work magic — single quotes stay honest. Five lines to trace.
Your predicted output — one line per console line
Hint: Only double-quoted strings interpolate — the single-quoted line prints its braces literally. And "Ruby" * 2 repeats without any space between.
01Only double-quoted strings interpolate #{...}.
02upcase, reverse and friends return NEW strings — the original stays put.
03"ha" * 3 repeats text; + glues strings together.
04length counts every character, spaces included.
05to_s and to_i convert between text and numbers.