-3

现在,我有以下内容:

<% @headlines.css('a').each do | headline | %>
   <%= headline.text %>
<% end %>

<% @top_stories.css('a').each do | top_story | %>
   <%= top_story.text %>
<% end %>

Nokogiri代码)

哪个输出:

"
    Heat vs. Bulls, Lakers vs. Clippers on opening night

    Free Agent Tracker

    Player movement
"

"

"
     Heat-Bulls, Lakers-Clippers on opening night 

     Closer look at sked 

     Most intriguing 

     Official release 

     Suns' Beasley arrested for suspected drugs 
" 

我想把这两个字符串变成一个红宝石哈希。像这样的东西:

{:headlines => ['Kobe ahead of schedule'], etc etc, :top_stories: ['Ex-Lebron pest Stevenson pinning to join Heat', etc etc] } 

如何做到这一点?

4

1 回答 1

1
<%= hash_res %>, <%= headline %> = {}, ''
<% @headlines.css('a').each do | headline | %>
    <%= headline %> << <%= headline.text %>
<% end %>
<%= head_res[:headlines] %> = headline

# Do the same thing for the below
<% @top_stories.css('a').each do | top_story | %>
    <%= top_story.text %>
<% end %>
于 2013-08-07T04:09:25.193 回答