15. String and string methods (Intro)


#1

Declare a variable name and set it equal to a string containing your name. Call .downcase on your name to make it all lower case, call .reverse on your lowercase name to make it backwards, then call .upcase on your backwards name to make it ALL CAPS.

In Ruby, you can do this two ways: each method call on a separate line, or you can chain them together, like this:

name.method1.method2.method3

So the 2nd way is:

name = “Mr.poopybutthole”.downcase.reverse.upcase

My question is how does the first method look like in code?

Is it like this?(if it is, makes little sense to copy paste it so much)

name = “Mr.poopybutthole”.downcase
name = “Mr.poopybutthole”.downcase.reverse
name = “Mr.poopybutthole”.downcase.reverse.upcase


#2

IMHO, the wording of the exercise is bit unclear. I think, it can be interpreted in two ways:

(1)

name =
“Mr Potty Mouth”
.downcase
.reverse
.upcase

(2)

name = "Mr Potty Mouth"
name = name.downcase
name = name.reverse
name = name.upcase

To be honest, I don’t see the point in both solutions…


#3

Yeah, the second one looks like what they meant.
The first one looks like a verticle version of name = “Mr.poopybutthole”.downcase.reverse.upcase.

Thank you for your reply :slight_smile: !


#4

Chaining lots of calls together can be a recipe for disaster. We never know when we could get an unintended side effect (one of the functions returning a value we didn’t expect) and it would be hard to figure out where the problem arose.
By doing one call at a time we can identify trouble easier


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.