When learning Ruby on Rails, sometimes you just need to get the current year as a number. I posted one example on why this is a useful way on a real-life website in the 2011 post on how to automatically update copyright notices.
In this article, I will show you some methods for getting the current year, such as the number
2015. I will then show you how to benchmark the methods to determine which is the fastest method for you, given your machine and Ruby version.
Okay, just how do I get the Current Year in Ruby?
It’s easy. Just use any of the Date/Time objects and call the
year method, like this:
1 2 3 4 5 6 7 8