代码之家  ›  专栏  ›  技术社区  ›  Chris Kimpton

ruby noob:/usr/lib/ruby/1.8/rss/rss.rb:922:in“有没有需要的元素?”:未定义的方法

  •  0
  • Chris Kimpton  · 技术社区  · 15 年前

    抱歉,这可能是一个基本的/愚蠢的/noob问题-我只是在尝试修改现有的Ruby脚本-它在我的Mac上运行,但是没有在Ubuntu9.04上运行。

    错误是:

    /usr/lib/ruby/1.8/rss/rss.rb:922:in `have_required_elements?': undefined method `have_required_elements?' for "App Store Reviews for ":String (NoMethodError)
        from /usr/lib/ruby/1.8/rss/maker/base.rb:188:in `any?'
        from /usr/lib/ruby/1.8/rss/rss.rb:922:in `each'
        from /usr/lib/ruby/1.8/rss/rss.rb:922:in `any?'
        from /usr/lib/ruby/1.8/rss/rss.rb:922:in `have_required_elements?'
        from /usr/lib/ruby/1.8/rss/maker/base.rb:188:in `all?'
        from /usr/lib/ruby/1.8/rss/rss.rb:917:in `each'
        from /usr/lib/ruby/1.8/rss/rss.rb:917:in `all?'
        from /usr/lib/ruby/1.8/rss/rss.rb:917:in `have_required_elements?'
        from /usr/lib/ruby/1.8/rss/rss.rb:962:in `tag'
        from /usr/lib/ruby/1.8/rss/rss.rb:884:in `to_s'
        from /usr/lib/ruby/1.8/rss/rss.rb:924:in `have_required_elements?'
        from /usr/lib/ruby/1.8/rss/maker/base.rb:188:in `all?'
        from /usr/lib/ruby/1.8/rss/rss.rb:917:in `each'
        from /usr/lib/ruby/1.8/rss/rss.rb:917:in `all?'
        from /usr/lib/ruby/1.8/rss/rss.rb:917:in `have_required_elements?'
        from /usr/lib/ruby/1.8/rss/rss.rb:962:in `tag'
        from /usr/lib/ruby/1.8/rss/rss.rb:1284:in `tag'
        from /usr/lib/ruby/1.8/rss/rss.rb:884:in `to_s'
        from ./appstore_reviews:215:in `write'
        from ./appstore_reviews:215
        from ./appstore_reviews:214:in `open'
        from ./appstore_reviews:214
    

    它使用Ruby的rss位并试图写出rss文件。文件写入行出错:

    ...
    version = "2.0"
    destination = "appreviews_"+ARGV[0]+".xml"
    puts destination
    content = RSS::Maker.make(version) do |m|
    m.items.do_sort = true
    
    # a simple command-line presentation
    software.keys.sort.each do |software_key|
    
    m.channel.title = "App Store Reviews for ",software_key
    m.channel.link = "http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=",ARGV[1],"&mt=8" # need to put in link to itunes
    m.channel.description = "App Store Reviews for ",software_key
    ...
    
    File.open(destination,"w") do |f|
    f.write(content)
    end
    

    这是基于iPhone应用程序审查欺诈代码: link text

    加入一些基本的RSS提要 link text

    提前感谢您提供任何提示/建议。 克里斯

    1 回复  |  直到 15 年前
        1
  •  1
  •   Antti Tarvainen    15 年前

    错误消息是关于字符串没有方法“have_required_elements?”.

    根据 http://www.ruby-doc.org/core-1.9/classes/RSS/Element.html rss::element有一个同名的方法。您可能在某个时刻调用了一个参数类型错误的方法。

    此行看起来可疑:

    m.channel.title = "App Store Reviews for ",software_key
    

    是否尝试连接两个字符串?在这种情况下,应该使用加号操作,而不是逗号。这里的逗号隐式生成一个数组。