I'm newish to ruby, used to JS and C#, dealing with nested block and i have 2 'loops' here which should print the exact same thing.
page.search( "//div[@id='mw-content-text']" ).search("p").find do |p|
puts p.inner_text.gsub(/[^a-z ]/i, '').split( ' ' )
end
page.search( "//div[@id='mw-content-text']" ).search("p").find do |p|
p.inner_text.gsub(/[^a-z ]/i, '').split( ' ' ).each do |word|
puts word
end
end
They both start by getting the all the paragraph tags in a page, then iterating through them. The first acts as expected, but when i try to iterate through each word with a nested block, i then only get one result from the outer block. it's as if the first 'end' is breaking the outer block or something. Is this normal ruby behaviour? have i missed something obvious?
Thanks for your help.
Simon.