为什么此代码不使用 ruby-mbox gem 解析 mbox 文件?
我通过执行 gem install ruby-mbox 安装 ruby-mbox
运行此:
#!/usr/bin/ruby
require 'rubygems'
require 'mbox'
m = IO.read('test.eml')
puts m.size
m = Mbox.new(m)
puts m
产生此异常(在第 7 行):
/Library/Ruby/Gems/1.8/gems/ruby-mbox-0.0 .2/lib/mbox/mbox.rb:45:in `initialize': uninitializedconstant Mbox::StringIO (NameError)
我已经证明“m”被分配了一个包含文件内容的字符串,只是在调用 Mbox.new(m) 之前。
看起来 Mbox::StringIO 应该由尚未定义。
这里出了什么问题?
Ruby 版本:(
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
这是 OS X 10.6.6 上安装的默认 ruby)
I installed ruby-mbox by doing gem install ruby-mbox
Running this:
#!/usr/bin/ruby
require 'rubygems'
require 'mbox'
m = IO.read('test.eml')
puts m.size
m = Mbox.new(m)
puts m
produces this exception (at line 7):
/Library/Ruby/Gems/1.8/gems/ruby-mbox-0.0.2/lib/mbox/mbox.rb:45:in `initialize': uninitialized constant Mbox::StringIO (NameError)
I have proved that "m" is assigned a string containing the contents of the file, just before Mbox.new(m) is called.
It looks as though the Mbox::StringIO should have been defined by hasn't been.
What's going wrong here?
Ruby version:
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
(That's the default ruby installed on OS X 10.6.6)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
抱歉,大家,我应该在发帖之前仔细看看...
修复了它:
只需插入行 require 'stringio' 即可:
看起来 stringio 被假定已加载 - 但实际上并非如此由 ruby-mbox 显式加载...
奇怪的是,示例脚本也不加载它...
Sorry people, I should have looked harder before posting here...
Fixed it:
Just inserted the line require 'stringio' to give this:
It looks like stringio is assumed to be loaded - but isn't loaded explicitly by ruby-mbox...
Oddly, the example scripts don't load it either...