Ruby is object-oriented, modelled after Smalltalk mostly. So
irb(main):001:0>10.class
=> Integer
So you’ll just have implement the method “years” on the Integer (or something more generic like Numeric) class and then “ago” on whatever class the years method returned.
You might imagine that you can do something like 10.years().ago() in python but the parser prevents you:
Ruby is object-oriented, modelled after Smalltalk mostly. So
irb(main):001:0> 10.class => IntegerSo you’ll just have implement the method “years” on the Integer (or something more generic like Numeric) class and then “ago” on whatever class the years method returned.
You might imagine that you can do something like 10.years().ago() in python but the parser prevents you:
>>> 10.years File "<python-input-0>", line 1 10.years ^ SyntaxError: invalid decimal literalDoesn’t seem like it would have to prevent it, back in ruby:
irb(main):001:0> 10.0.class => FloatRuby is a pretty cute language in my opinion, and I find it sad that python kinda drove over it.
That’s just syntax.
>>> 10 .yearsTraceback (most recent call last): File "<stdin>", line 1, in <module>AttributeError: 'int' object has no attribute 'years'