Today I came across the strange ruby syntax in the Rational class:
Rational(a,b)
(Notice the absence of the .new()
portion compared to the normal Ruby syntax). What does this mean, precisely, compared to the normal new
syntax? More importantly, how do I implement something like this in my own code, and why would I implement something like this? Specifically for the Rational
class, why is this syntax used instead of the normal instantiation? And why is the new
method private in the rational class? (And how/why would I do this in my own ruby code?)
Thanks in advance for your answers, especially since I've asked so many questions.