我找到了一些Ruby代码,它们使用了:
require "active_support/core_ext/time"
require "active_support/core_ext/numeric"
在我的macOS Monterey Mac上,我还没有rails或rvm
,如果我安装rvm
,它需要Homebrew安装一个新的Ruby,这可能会使事情进一步复杂化,所以对于系统Ruby(ruby 2.6.8p205
),如何安装active_support/core_ext/time
以便使用它?
我看了this question,它没有解决这个问题。
我可以安装rails:
gem install rails
但是,我真的必须使用sudo
来完成吗?(我尽量减少使用sudo
来保持系统更安全)。
3条答案
按热度按时间apeeds0o1#
使用
sudo
安装gem是一个非常糟糕的主意最好在你的系统中使用一些Ruby管理器
例如:
您还可以使用docker来隔离项目
当你得到一些使用这个变体的Ruby时,你可以用
Gemfile
安装ActiveSupportgem,或者只使用terminal命令然后,您可以在此处选择所需的文件:
https://github.com/rails/rails/tree/main/activesupport/lib
例如,您需要所有
Time
monkeypatches它在这里:
https://github.com/rails/rails/blob/main/activesupport/lib/active_support/core_ext/time.rb
因此,您需要用途:
14ifxucb2#
为了补充@mechnicov的答案,是的,首先安装像RVM这样的东西,然后
你可以用
(假定加载https://github.com/rails/rails/blob/main/activesupport/lib/active_support/core_ext/time.rb中的所有内容)
如果您使用的是最新版本的Ruby,则根据您需要的数值,而不是:
它应该装载https://github.com/rails/rails/blob/main/activesupport/lib/active_support/core_ext/numeric.rb
您可以用途:
如Rails docs中。
您还可以通过以下方式包含所有内容:
如this Rails docs。有关详细信息,请参阅https://github.com/rails/rails/blob/main/activesupport/lib/active_support/all.rb。
yzckvree3#
你可以做同样的事情使用
sudo gem install active_support
你必须使用sudo,因为你正在写一个默认的系统库。
我强烈推荐使用rbenv或rvm,这样你就不会经常干预系统Ruby。它稍微需要更多的设置,但Homebrew和RVM都是众所周知的支持库。