learn_ruby_ch4_pt2 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Concatenate “Hello,” space, “Matz”, and “!” three ways

A

“Hello,” “ “ “Matz” “!”

“Hello,” + “ “ + “Matz” + “!”

“Hello,”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Concatenate with the method

A

h = “Hello, “
m = “Matz!”
h.concat(m)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Make a string immutable

A

greet = “Hello, Matz!”
greet.freeze

greet. concat(“!”) # => TypeError: can’t modify frozen string
greet. frozen? # => true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Check if a string contains a string

A

speaker = “King Richard III”

speaker[‘King’] # => “King”

speaker[‘yada’] # => nil

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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!”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly