ruby 使用 RbConfig 而不是过时和弃用的 Config

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13693713/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 05:34:11  来源:igfitidea点击:

Use RbConfig instead of obsolete and deprecated Config

rubyruby-on-rails-3.2rubygems

提问by dsilver829

When I run my Rails app in WEBrick on Ubuntu, after upgrading to ruby-1.9.3-p327, I receive the following error:

当我在 Ubuntu 上的 WEBrick 中运行 Rails 应用程序时,升级到 ruby​​-1.9.3-p327 后,我收到以下错误:

[rake --tasks] /home/dsilver/.rvm/gems/ruby-1.9.3-p327/gems/em-dir-watcher-0.9.4/lib/em-dir-watcher.rb:7: Use RbConfig instead of obsolete and deprecated Config.

[rake --tasks] /home/dsilver/.rvm/gems/ruby-1.9.3-p327/gems/em-dir-watcher-0.9.4/lib/em-dir-watcher.rb:7: 使用 RbConfig而不是过时和弃用的配置。

Any idea what's going on?

知道发生了什么吗?

I've seen some posts connecting this to ImageMagick on Windows. I am on Ubuntu, but the app does use ImageMagick, and the ImageMagick functionality appears to have broken since the ruby upgrade from 1.9.2 to 1.9.3. I suspect a connection.

我已经看到一些帖子将其连接到 Windows 上的 ImageMagick。我在 Ubuntu 上,但该应用程序确实使用了 ImageMagick,而且自从 ruby​​ 从 1.9.2 升级到 1.9.3 以来,ImageMagick 功能似乎已经损坏。我怀疑有联系。

Thanks!

谢谢!

采纳答案by matt

The Configmodule has been renamed to RbConfig. It's still possible to use the old name, for backwards compatibility, but Ruby issues a warningif you do.

Config模块已重命名为RbConfig. 为了向后兼容,仍然可以使用旧名称,但如果这样做,Ruby 会发出警告

The em-dir-watchergem uses the old name, and so you see the warning when it's loaded. Someone has already sent a pull requestfixing this, however the last update to em-dir-watcherwas over two years ago so it might not get merged.

em-dir-watcher宝石使用旧名称,所以你看到警告时,它的加载。有人已经发送了一个pull request 来解决这个问题,但是最后一次更新em-dir-watcher是在两年多前,所以它可能不会被合并。

This is a warning that is generated, not an error, so your code should actually still work okay. If you really want to get rid of the warning you could add something like this before you require 'em-dir-watcher':

这是生成的警告,而不是错误,因此您的代码实际上应该仍然可以正常工作。如果你真的想摆脱警告,你可以在你之前添加这样的东西require 'em-dir-watcher'

Object.send :remove_const, :Config
Config = RbConfig

This defines Configto be the same as RbConfig, which is what Ruby does anyway, but prevents the warning.

这定义Config为与 相同RbConfig,无论如何 Ruby 都会这样做,但会阻止警告。

回答by Daniel Antonio Nu?ez Carhuayo

You can do (not recommended):

你可以这样做(不推荐):

Go to the file ../lib/ruby/1.9/rbconfig/obsolete.rb

转到文件../lib/ruby/1.9/rbconfig/obsolete.rb

Edit the file, the change is commenting the line #warn ...

编辑文件,更改是注释#warn ...

With that change, eliminated the advice "warn"

随着这一变化,消除了建议“警告”