[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Strange behavior with Sequel + RSS::Parser

Luis Parravicini

10/23/2007 12:51:00 PM

Hi

I'm having a strange behavior when using RSS::Parser after requiring
the sequel gem. After doing a require 'sequel', the number of news
items is always 0. The script below is a small test which reads a rss
feed with 6 items and prints the number of news items parsed. The
first puts is after requiring 'rss', and the last puts is after
requiring 'sequel'.

# require 'rss'
read 6, should be: 6
# require 'rubygems'
read 6, should be: 6
# require 'sequel'
read 0, should be: 6

I've run this script with:
sequel 0.2.1.1 and ruby 1.8.5 (2006-08-25) [i486-linux]
sequel 0.3.0.1 and ruby 1.8.6 (2007-06-07 patchlevel 36) [i486-linux]

Anyone seen this before?

Thanks


---[begin] test_case.rb -----------------------------------------
ITEMS = 6

def rss_items
rss = RSS::Parser.parse(IO.readlines('feed.xml').join)
rss.items.size
end

def compare(items)
puts "read #{items}, should be: #{ITEMS}"
end


require 'rss'
compare(rss_items)

require 'rubygems'
compare(rss_items)

require 'sequel'
compare(rss_items)
---[end] test_case.rb -----------------------------------------

---[begin] feed.xml -----------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="0.91">
<channel>
<title/>
<description/>
<link/>

<item/>
<item/>
<item/>
<item/>
<item/>
<item/>

</channel>
</rss>
---[end] test_case.rb -----------------------------------------

--
Luis Parravicini
http://ktulu.co...

2 Answers

Sharon Rosner

10/23/2007 2:16:00 PM

0

> I'm having a strange behavior when using RSS::Parser after requiring
> the sequel gem. After doing a require 'sequel', the number of news
> items is always 0. The script below is a small test which reads a rss
> feed with 6 items and prints the number of news items parsed. The
> first puts is after requiring 'rss', and the last puts is after
> requiring 'sequel'.

I've traced this problem down to the ruby2ruby gem, which is used by
Sequel. The Ruby2Ruby code contains the following trick:

class NilClass # Objective-C trick
def method_missing(msg, *args, &block)
nil
end
end

Try to add this bit to your code instead of requiring Sequel and
you'll see the same behavior. It seems the RSS parser relies on nil
raising an error for invalid calls, and the monkey patch for
NilClass#method_missing screws things up.

I suggest you contact Ryan Davis, the author of Ruby2Ruby, for further
help.

best
Sharon


Luis Parravicini

10/23/2007 4:24:00 PM

0

On 10/23/07, Sharon Rosner <ciconia@gmail.com> wrote:
> I suggest you contact Ryan Davis, the author of Ruby2Ruby, for further
> help.

I've mailed Ryan about it, thanks Sharon!

--
Luis Parravicini
http://ktulu.co...