Home > OS >  In Ruby, how to add active_support/core_ext/time?
In Ruby, how to add active_support/core_ext/time?

Time:05-18

I found some Ruby code that made use of:

require "active_support/core_ext/time"
require "active_support/core_ext/numeric"

On my Mac with macOS Monterey, I don't have rails or rvm yet, and if I install rvm, it requires Homebrew to install a new Ruby and it may complicate things further, so with the system Ruby (ruby 2.6.8p205), how can active_support/core_ext/time be installed so that it can be used?

I looked at this question and it doesn't solve the problem.

I recalled I can install rails:

gem install rails

However, is it true that I have to use sudo to do it? (I try to minimize the use of sudo to keep the system more secure).

CodePudding user response:

You can do the same thing using

sudo gem install active_support

You have to use sudo because you are writing to a default system library.

I would highly recommend using rbenv or rvm so you aren't meddling with the system Ruby constantly. It is slightly more setup, but both Homebrew and RVM are well known and supported libraries.

CodePudding user response:

Using sudo to install gem is completely bad idea

It's better to use some ruby manager in your system

For example:

You can also use docker to isolate project

When you get some Ruby using one of this variant, you can install ActiveSupport gem with Gemfile or just with terminal command

gem install activesupport

Then you can choose file(s) that will be required here:

https://github.com/rails/rails/tree/main/activesupport/lib

For example you need all Time monkeypatches

It is here:

https://github.com/rails/rails/blob/main/activesupport/lib/active_support/core_ext/time.rb

So you need to use:

require "active_support/core_ext/time"
  • Related