Including Rails Time Helpers in a Ruby Ruby-Free Application

First of all, I use Rails for development, and I like the 1.hour.from_now , 34.minutes and 24.megabytes that Rails has built into it. However, now I am creating a Ruby application in which these helpers will be enjoyable. Is it possible to simply get these helpers in a Ruby application without having to contribute the entire Rails structure?

+6
source share
1 answer

These methods are taken from the ActiveSupport Kernel Extension (specifically for Integer and Numeric), so you can simply require them:

 require 'active_support/core_ext/integer/time' require 'active_support/core_ext/numeric/time' 

Or if you want all major ActiveSupport extensions to provide:

 require 'active_support/core_ext' 

Or if you want all ActiveSupport (including internal extensions):

 require 'active_support/all' 

Of course, you must provide activesupport gem .

+9
source

Source: https://habr.com/ru/post/913558/


All Articles