Ruby Is Forgiving Of Spaces After Dot

less than 1 minute read

You’d call methods on an object like so:


This is how we came to learn to see Object-Oriented Programming in practice.

I know that we can chain methods by placing each methods in a new line, like so:

res = "prasanna"

p res
# => "prasanna"

But recently I found that, there can be spaces before and/or after the ‘dot’ too.

Mixing this and the previous scenario:

res = "prasanna" . upcase . downcase .split('') . join

p res
# => "PRASANN"

It works!

But remember, you’ll never be lauded if you use this in a real project with collaborators!