Ruby';每个';块

Ruby';每个';块,ruby,Ruby,我正在做一个小应用程序,从XML提要下载torrents 我能够解析XML文件,但数组有点问题 我创建了一个包含我想要下载和迭代的torrents链接的数组。但是,在每个块中,项不是字符串。Ruby说对象的类型是数组 一些代码片段: series = ['Fringe', 'Supernatural', 'The.Walking.Dead', 'Dexter', 'Game.of.Thrones', 'Merlin.2008'] links = ['h

我正在做一个小应用程序,从XML提要下载torrents

我能够解析XML文件,但数组有点问题

我创建了一个包含我想要下载和迭代的torrents链接的数组。但是,在
每个
块中,项不是字符串。Ruby说对象的类型是数组

一些代码片段:

series = ['Fringe', 'Supernatural', 
          'The.Walking.Dead', 'Dexter', 
          'Game.of.Thrones', 'Merlin.2008']
links = ['http://torrentday.com/asdada/asdad/torrent',
         'http://torrentday.com/t5terter/Fringe.s08e02.torrent']
links.each do |link|
  series.each do |serie|
    if link.include? serie # doesn't work, because the type 
                           # of link is Array, not String.
      downloader.download(link)
      break
    end
  end
end

您的代码对我来说似乎工作正常:

> series = ['Fringe', 'Supernatural', 
*           'The.Walking.Dead', 'Dexter', 
*           'Game.of.Thrones', 'Merlin.2008']
=> ["Fringe", "Supernatural", "The.Walking.Dead", "Dexter", "Game.of.Thrones", "Merlin.2008"]
> links = ['http://torrentday.com/asdada/asdad/torrent',
*          'http://torrentday.com/t5terter/Fringe.s08e02.torrent']
=> ["http://torrentday.com/asdada/asdad/torrent", "http://torrentday.com/t5terter/Fringe.s08e02.torrent"]
> links.each do |link|
*   series.each do |serie|
*     if link.include? serie # doesn't work, because the type 
>       puts "#{link} included #{serie}"
>     end
>   end
> end
http://torrentday.com/t5terter/Fringe.s08e02.torrent included Fringe
=> ["http://torrentday.com/asdada/asdad/torrent", "http://torrentday.com/t5terter/Fringe.s08e02.torrent"]

它正确地执行了
if
语句的主体,用于
serie
link

的一个匹配组合。解析就是这样做的:块内的类型就是集合中的类型。还包括
links
series
的模拟数据源。就像现在一样。。。这是一个神奇的8球问题。这只是一个例子,@niklas-baumstark.code对我很有用。为什么不呢?我使用的是ruby 1.8,这有什么问题吗?