One of the items on my 2015 To Do List was to become a Rails contributor.

Recently, whilst writing a small app to track the interest and repayments of a loan, I needed to know the number of days in a given year. This was required to calculate the daily rate of interest for the loan based on its APR.

The first thing I did was run a quick search against the Ruby documentation, and then against the Rails documentation, to see whether this method already existed. I found the days_in_month method, but nothing to provide the days in a year. No big deal though, if you add 337 to the number of days in February, you get the number of days in the year.

So, I opened up the Time class and monkey-patched it with a small method which did exactly this and merrily continued building my app:

class Time
  def days_in_year(year = current.year)
    days_in_month(2, year) + 337
  end
end

A little later, I figured I probably wasn’t the only person who ever needed this method. Why do we have a days_in_month method without a days_in_year method anyway? So why not send a pull request to the Rails project asking to merge in my method?

And thus, my first contribution to Ruby on Rails was born. I forked the project, wrote some tests, dropped in my new method, and then within a day or so my pull request was accepted!

I was quite amused to see that Gregg Pollack and Dan Bickford took the time to mention my tiny contribution in their Ruby5 Podcast. Thanks guys!

Seems I also got a mention in the official Rails blog, and now have my very own contributor page.

Whilst I can certainly put a tick next to my To Do item for becoming a Rails contributor, I think need to contribute something somewhat more substantial before I can really mark that as being completed. But it’s a start …