AnyCompiler

Strings

Double-quoted Ruby strings interpolate: #{expression} inside one is evaluated and replaced with its value, string or not. Because strings are objects, the usual case-conversion and inspection operations are methods you call on the string itself, not separate functions.

name = "World"
greeting = "Hello, #{name}!"
puts greeting
puts greeting.length
puts greeting.upcase
puts greeting.reverse
Output
Hello, World!
13
HELLO, WORLD!
!dlroW ,olleH

.split breaks a string into an array of pieces around a separator — one of the most common bridges from "a string" to "a list of things to iterate over", which the next few lessons build on heavily.

puts "a,b,c".split(",").inspect
Output
["a", "b", "c"]

inspect renders a value the way Ruby would write it back as code — useful for seeing an array's actual contents instead of however puts would print it. Next: everything is an object — the idea that even a number responds to methods, which strings and symbols have already been quietly demonstrating.

Practice exercise

Create word = "ruby". Print its uppercase version using .upcase, then print its length using .length.