Methods upcase, reverse, nextand swapcasereturn objects String, and all of these methods are suitable for ... you guessed it, Stringobjects!
When you call a method (most often, for example 99.9999% of the time), it returns an object. This object has methods defined on it that can then be called, which explains why you can do this:
"Test".upcase.reverse.next.swapcase
You can even call reverseas many times as you want:
"Test".reverse.reverse.reverse.reverse.reverse.reverse.reverse.reverse
That's because it returns the same type of object, object String!
But you cannot do this with yours MyClass:
x = My_Class.new
x.a.b.c
a , b, . , , MyClass . , a , :
def a
@b += 2
self
end
, b self, c MyClass. , c , . self, . Schrödinger cat. , .