learn_ruby_ch4_pt2 Flashcards
1
Q
Concatenate “Hello,” space, “Matz”, and “!” three ways
A
“Hello,” “ “ “Matz” “!”
“Hello,” + “ “ + “Matz” + “!”
“Hello,”
2
Q
Concatenate with the method
A
h = “Hello, “
m = “Matz!”
h.concat(m)
3
Q
Make a string immutable
A
greet = “Hello, Matz!”
greet.freeze
greet. concat(“!”) # => TypeError: can’t modify frozen string
greet. frozen? # => true
4
Q
Check if a string contains a string
A
speaker = “King Richard III”
speaker[‘King’] # => “King”
speaker[‘yada’] # => nil
5
Q
Use indexing on a line
line = “A horse! a horse! my kingdom for a horse!”
A
line = “A horse! a horse! my kingdom for a horse!”
line[7] # => “!”
line[18, 23] # => “my kingdom for a horse!”
line[18, 23].capitalize # => “My kingdom for a horse!”