I just had to answer this because it is a fun Ruby exercise.
Adding methods to a class can be done in many ways, but one of the easiest ways is to use some Ruby reflection and evaluation functions.
Create this file in the lib folder as lib / date_methods.rb
module DateMethods def self.included(klass)
Now just plug it into any models he needs
class CourseSection < ActiveRecord::Base include DateMethods end
When enabled, the module will look at any date columns and generate formatted_ methods for you.
Find out how this Ruby works. It is very funny.
However, you should ask yourself if necessary. I donโt think itโs personal, but again it was fun to write.
-b -
Brian hogan
source share