Stringing together methods


#1

What am I missing with this code to get it to run if I remove the comment from the end and run that as code?
When I run this with the method string commented out, it provides the expected results. When I make the last line code instead of comment, this is the error I receive: undefined method `method1’ for “Melinda”:String
Did you mean? method
methods

I have tried to define each method as a String, and it gives me a different error. Any guidance would be great. Thanks!!!

name = “Melinda”

method1 = name.upcase
puts method1

method2 = name.downcase
puts method2

method3 = name.reverse
puts method3

#puts name.method1.method2.method3


#2

Link to exercise, please. Thanks.


#3

https://www.codecademy.com/courses/learn-ruby/lessons/introduction-to-ruby/exercises/strings-and-string-methods?action=resume_content_item


#4

The reverse step is number 2, not 3.


#5

The calls on the individual objects is not where I am having trouble. I can not get the combined methods to work. I adjusted the code to put the methods in the same format as suggested. It does not change that the output does not function. The methods each produce the expected outcome. When I remove the comment and try to run the last line, it throws the error.


#6

What you have are three strings, not methods. That is why they cannot be chained.

name.downcase.reverse.upcase

#7

Thank you. Changing that got it to run. I was taking the example too literally.