Category: Ruby

You need Ensurance

Been plowing through a massive refactoring of a legacy Rails app.   One of the things I find myself doing all the time now is ensuring.  It’s a handy little concern that works like this: In the old days, we’d do this: class SomeClass def some_method(person_id) person = Person.find(person_id)   # then proceed to do […]

Iterating a Date Range in Ruby by Day

I wanted to take a date range and iterate over it to produce results by day, but when I went to check the results, there were results by second. def my_date_thing(a_range) a_range.each do |date| # something interesting by date end end   my_date_thing(10.days.ago .. 0.days.ago) Turns out, that by default those cool days.ago methods return […]