DEV Community

thomasprinn
thomasprinn

Posted on

TIL (Ruby Fundamentals)

Due to some IRL mishaps I'm a bit behind still, but I was able to finish up the Codeacademy Ruby course, the What, why, and how assignment, and go through the Ruby modules on Canvas.

I noticed something interesting:
When using

self.pp(2.add(3))
Enter fullscreen mode Exit fullscreen mode

if I add

print self
Enter fullscreen mode Exit fullscreen mode

to the code,
why is the output for print self "main"?

It turns out that self is a special object - the main object for the example, so Ruby is telling me exactly that.

I also didn't know that there was a difference between using print and pp, so I'll practice it.

Comparing objects and methods to nouns and verbs helps a lot.
There are many interesting terms such as "pretty print", "syntactic sugar" that make learning Ruby a little more unique and easy to remember compared to other programming languages.

Top comments (0)