Active support is a set of libraries provided with rails, active support extends some of the classes in Ruby, and this time we'll look at some of the most common features.
1. Extension of the number type
The Fixnum class adds two methods: even and odd?
The scaling method is also added:
Puts 20.bytes #=> 20
Puts 20.kilobytes #=> 20480
Puts 20.megabytes #=> 20971520
Puts 20.gigabytes #=> 21474836480
Puts 20.terabytes #=> 21990232555520
There is also a time based scaling that converts accepted values to corresponding seconds, the month () and year () methods get approximate values, and the month is assumed to be 30 days, and is assumed to be 365 days.
Puts 20.minutes #=> 1200
Puts 20.hours #=> 72000
Puts 20.days #=> 1728000
Puts 20.weeks #=> 12096000
Puts 20.fortnights #=> 24192000
Puts 20.months #=> 51840000
Puts 20.years #=> 630720000
2. Expansion of time
The time class adds some methods to help us with the computation
now = Time.now
Puts now
Puts Now.ago (3600)
Puts Now.at_beginning_of_day
Puts Now.at_beginning_of_month
Puts Now.at_beginning_of_week
Puts Now.at_beginning_of_year
Puts Now.at_midnight
Puts Now.change (: Hour => 13)