I primarily use Rails to develop in and I love the 1.hour.from_now
, 34.minutes
, and 24.megabytes
helpers that Rails has built into it. However right now I am building just a Ruby application having these helpers would be nice. Is it possible to just get these helpers in a Ruby application without having to bring in the whole Rails framework?
These methods come from ActiveSupport's core extensions (specifically ones on Integer & Numeric), so you can just require them:
require 'active_support/core_ext/integer/time'
require 'active_support/core_ext/numeric/time'
Or if you want all core extensions ActiveSupport provides:
require 'active_support/core_ext'
Or if you want all of ActiveSupport (core extensions included):
require 'active_support/all'
Of course you have to ensure the activesupport
gem is installed.