Question about .upcase and .downcase


#1



Lesson 1.9 .upcase and .downcase


is puts always required in the .upcase and .down case? Also can it be used with print?

Replace this line with your code.
puts "eric".upcase
print "eric".upcase

`


#2

is puts always required in the .upcase and .down case? Also can it be
used with print?

Replace this line with your code.
puts "eric".upcase
print "eric".upcase

'puts' is a method invocation and as such does not even see the upcase
call.

Your code is a short form of

(self.print("eric".upcase))

i.e. the method String#upcase is executed on the string "eric", and the
result is then handed over to print, which is executed on the object
self (the implicit receiver). Every method method invocation needs a
receiver, and if the receiver is self, it can be omitted.

To find out, what kind of beast self is, type

self.class.name

#3

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