In my previous post, I have explained how to extend
In this post, I will explain how to extend core
rails classes in
Create a file
lib folder and add your extension code.
Below is the example to extend
Create a rails
In the initializer load the date_extensions.rb like
Now the rails will load the date_extensions.rb on boot and all the date methods we created will be available for use.
Above date extension has got a method
month_year to get only month and year from the date in format
%b/%Y' as string.
Similary a class method is defined to get date from the month_year string.
 pry(main)> today = Date.today => Mon, 25 Jul 2016  pry(main)> today.month_year => "Jul/2016"  pry(main)> Date.month_year_to_date 'Jul/2016' => Fri, 01 Jul 2016