From: John Joyce Date: 2007-04-14T09:13:04+09:00 Subject: Re: Hpricot innerTEXT? On Apr 13, 2007, at 10:48 PM, Brian Candler wrote: > On Fri, Apr 13, 2007 at 10:40:05PM +0900, chickenkiller wrote: >> doc = Hpricot(File.open("rdf.xhtml")) >> >> puts (doc/"item"/"dc:subject").inner_text >> # html imported webpagedesign >> >> (doc/"item").each do |t| >> puts((t/"dc:subject").inner_text) >> end >> # html imported webpagedesign >> >> (doc/"item").each do |t| >> puts (t/"dc:subject").inner_text >> end >> # html imported webpagedesign >> # rdf.rb:12: warning: don't put space before argument parentheses >> # rdf.rb:12: undefined method `inner_text' for nil:NilClass >> (NoMethodError) >> # from rdf.rb:11:in `each' >> # from rdf.rb:11 >> >> I am wondering where the difference is between the two last blocks. >> Any ideas? > > Hmm, looks like this should be something that can be replicated > without > hpricot. > > $ cat x.rb > x = 3 > puts (x-5).abs > > 1.times do > puts (x-5).abs > end > $ ruby -v > ruby 1.8.4 (2005-12-24) [i486-linux] > $ ruby x.rb > x.rb:5: warning: don't put space before argument parentheses > 2 > -2 > x.rb:5: undefined method `abs' for nil:NilClass (NoMethodError) > from x.rb:4 > $ > > Congratulations, I think you've found a bug in the parser :-) I'll > post this > example to ruby-core. > > Regards, > > Brian. > Inside the do-end or {} block, use this: puts((x - 5).abs) It is more explicit, but correct and works. so, >>>> (doc/"item").each do |t| >>>> puts (t/"dc:subject").inner_html >>>> end >>>> will work as (doc/"item").each do |t| puts((t/"dc:subject").inner_html end