在Ruby中,如何添加Active_support/core_ext/time?

发布于 2025-01-29 16:41:35 字数 737 浏览 2 评论 0 原文

我找到了一些Ruby代码,可以使用:

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

Macos Monterey上的Mac上,我没有导轨或 rvm ,如果我安装 rvm ,它需要自家浏览器。要安装新的Ruby,并且可能会使事情变得更复杂,因此使用系统Ruby( Ruby 2.6.8p205 ),如何安装 Accem> Accem> active_support/core_ext/time 可以使用吗?

我看了看这个问题,它无法解决问题。

我回想起我可以安装导轨:

gem install rails

但是,我必须使用 sudo 做到这一点吗? (我尝试最大程度地减少 sudo 以保持系统更安全的使用)。

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).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

眼眸 2025-02-05 16:41:35

使用 sudo 安装宝石完全是一个坏主意。

最好在系统中使用一些Ruby Manager。

例如:

您也可以使用 docker 隔离项目。

当您使用这些变体之一获得一些Ruby时,您可以使用 gemfile 或AS as terminal命令安装ActiveSupport Gem:

gem install activesupport

然后您可以选择在此处需要的文件:

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

例如,您需要所有时间 monkeypatches。

因此,您需要使用:

require "active_support/core_ext/time"

Using sudo to install a gem is completely a bad idea.

It's better to use some Ruby manager in your system.

For example:

You can also use Docker to isolate the project.

When you get some Ruby using one of these variants, you can install the ActiveSupport gem with Gemfile or just with as 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.

There are in time.rb.

So you need to use:

require "active_support/core_ext/time"
爱的十字路口 2025-02-05 16:41:35

要添加到 >是的,首先安装

gem install activesupport

require "active_support/core_ext/time"

rvm 据称将所有内容加载在

如果您使用的是Ruby的最新版本,具体取决于您在数字中需要的内容,而不是:

require "active_support/core_ext/numeric"

据说它加载 numeric.rb ,您可以使用:

require "active_support/core_ext/numeric/time.rb"

Rails文档上的Ruby

您还可以包括以下所有内容:

require "active_support/all"

rails on rails文档上的这个ruby 。请参阅 有关详细信息。

To add to mechnicov's answer, yes, first install something like RVM, and then

gem install activesupport

And you can use

require "active_support/core_ext/time"

as before (which supposedly loads everything in time.rb)

If you are using a recent version of Ruby, depending on what you need in numeric, instead of:

require "active_support/core_ext/numeric"

which supposedly loads numeric.rb, you can use:

require "active_support/core_ext/numeric/time.rb"

as in the Ruby on Rails documentation.

You can also include everything by:

require "active_support/all"

as in this Ruby on Rails documentation. See all.rb for details.

断爱 2025-02-05 16:41:35

进行相同的操作

您可以使用 sudo gem安装Active_support

,因为您正在写入默认系统库,因此必须使用sudo。

我强烈建议使用 rbenv homebrewrer“ 。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文