Ruby:Ping.pingecho 缺失
Ruby 曾经有一个 Ping.pingecho
方法,但似乎(和 Ping
模块)已经消失了:
% rvm use 1.8.7
Using ~/.rvm/gems/ruby-1.8.7-p334
% ruby -rping -e 'p Ping.pingecho "127.0.0.1"'
true
% rvm use 1.9.2
Using ~/.rvm/gems/ruby-1.9.2-p180
% ruby -rping -e 'p Ping.pingecho "127.0.0.1"'
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- ping (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
% ruby -e 'p Ping.pingecho "127.0.0.1"'
-e:1:in `<main>': uninitialized constant Object::Ping (NameError)
它是否已转移到不同的库(那么应该做什么?我需要
加载它?),或者 它是否已被删除,并替换为不同的模块(那么我应该使用什么来确定IP是否可达?)。
Ruby used to have a Ping.pingecho
method, but it seems as if (and the Ping
module) have disappeared sometime:
% rvm use 1.8.7
Using ~/.rvm/gems/ruby-1.8.7-p334
% ruby -rping -e 'p Ping.pingecho "127.0.0.1"'
true
% rvm use 1.9.2
Using ~/.rvm/gems/ruby-1.9.2-p180
% ruby -rping -e 'p Ping.pingecho "127.0.0.1"'
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- ping (LoadError)
from <internal:lib/rubygems/custom_require>:29:in `require'
% ruby -e 'p Ping.pingecho "127.0.0.1"'
-e:1:in `<main>': uninitialized constant Object::Ping (NameError)
Has it moved to a different library (so what should I require
to load it?), or
has it been deleted, and replaced with a different module (so what should I use to determine whether a IP is reachable?).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不知道为什么或它去了哪里。 Rails 仍然有一个 Ping 类。稍作调整(使用类方法)将是:
Don know why or where it has gone. Rails still has a Ping class. A slight adaptation (to use a class method) would be:
我刚刚遇到这个问题。我用 net-ping gem 作为替代品。 gems/net-ping-1.7.7/examples/example_pingtcp.rb 中有一个清晰的 TCP ping 示例:
rubydoc.info 链接 在撰写本文时不起作用,但这里是模块源代码 (tcp.rb) 中的有用注释,
所以我交换了这个:
这样:
从旧的等效模块移动到新的等效模块有两个注意事项:
ping?< /code> 方法,而不仅仅是实例化。
I just encountered this issue. I settled with the net-ping gem as a replacement. It has a clear TCP ping example in gems/net-ping-1.7.7/examples/example_pingtcp.rb:
The rubydoc.info link at the time of this writing is not working, but here is a useful comment in the source of the module (tcp.rb)
So I swapped this:
With this:
There are two caveats in moving from the old to the new equivalent module:
ping?
method, rather than just instantiating.