2013-08-07 10 views
-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] } 

어떻게 수행 할 수 있습니까?

답변

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 %> 
관련 문제