Ruby RSS -- 为 RSS:REXMLListener 调用私有方法 send
我正在尝试将 RSS 解析器集成到我的 IRC 机器人中,并且我在网上找到了一些简单的代码,但是,如果我将此代码放入机器人中,我会得到以下信息:
Error: private method `send' called for #<RSS::REXMLListener:0x3d7c790>
我不确定为什么它给了我这个错误,因为它在 IRB 或其自己的私有脚本中工作正常。 这是代码,也是导致错误的行。
def fetch_rss_items(url, max_items = nil)
%w{open-uri rss/0.9 rss/1.0 rss/2.0 rss/parser}.each do |lib|
require(lib)
end
rss = RSS::Parser.parse(open(url).read) #This line is causing the error
rss.items[0...(max_items ? max_items : rss.items.length)]
end
I am trying to integrate a RSS parser into my IRC bot, and i've found some simple code to do so online, however, if i put this code in the bot, I get this:
Error: private method `send' called for #<RSS::REXMLListener:0x3d7c790>
I'm not sure why it gives me this error, as it works fine in IRB or in its own private script.
This is the code, and the line thats causing the error.
def fetch_rss_items(url, max_items = nil)
%w{open-uri rss/0.9 rss/1.0 rss/2.0 rss/parser}.each do |lib|
require(lib)
end
rss = RSS::Parser.parse(open(url).read) #This line is causing the error
rss.items[0...(max_items ? max_items : rss.items.length)]
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很确定,我也遇到了同样的问题:
问题是您在某处声明了函数
send
,并且:Ruby 的默认命名空间是 Object 类,您在默认命名空间中定义的方法被视为 Object 的私有方法
http://railsforum.com/viewtopic.php?id=31016
PS:有人知道如何避免此类错误吗?
I'm pretty sure, that I just had the same issue:
The problem is that somewhere you have declared function
send
, and:ruby's default namespace is the Object class, and methods you define in the default namespace are considered private methods of Object
http://railsforum.com/viewtopic.php?id=31016
P.S.: anyone knows how to avoid such bugs?