Forum: Ruby Cannot dump FeedNormalizer Feed objects using YAML

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F0e2e7181221d362a226abe48d46e0e0?d=identicon&s=25 Shajith C T (Guest)
on 2007-06-23 09:08
(Received via mailing list)
Hi,
I'm downloading and parsing an RSS/Atom feed using open-uri and
feed-normalizer and trying to save the parsed feed as yaml.

Sample code below:

%w(rubygems open-uri feed-normalizer yaml).each {|lib| require lib}
YAML.dump(FeedNormalizer::FeedNormalizer.parse(open("http://waxy.org/links/index.xml")))

Gives:

TypeError: can't dump anonymous class Class

I read elsewhere on the list about why Class-es cannot be dumped, but
I have no clue why trying to dump a FeedNormalizer::Feed object causes
this error(Don't know where to look).

Has anyone done this sort of thing before? Is there any painless
workaround to this?

Thanks in advance!
Shajith
3e0a00153a14c1c242be6f05f10fbdd5?d=identicon&s=25 Andy Smith (Guest)
on 2007-06-23 10:10
(Received via mailing list)
>
> Is there any painless workaround to this?
>

Either use Marshal.dump instead, or set parser to nil on the feed object
before YAMLification:

   feed = FeedNormalizer.parse(open("http://waxy.org/links/index.xml"))
   feed.parser = nil  # [1]
   YAML.dump(feed)    # now it should work...

   # [1] or maybe feed.parser = feed.parser.to_s if you don't
   # want to lose meta info.


I intend to fix this in the next release so that pre-serialization
object tampering isn't required :)

Hope that helps.

Andy
F0e2e7181221d362a226abe48d46e0e0?d=identicon&s=25 Shajith C T (Guest)
on 2007-06-23 10:19
(Received via mailing list)
On 6/23/07, Andy Smith <andy@tinnedfruit.org> wrote:
>
> Either use Marshal.dump instead, or set parser to nil on the feed object
> before YAMLification:

Ah, so that's what I need to zero out. I need to use YAML because I
want to keep the data human-inspectable.

Much thanks, and looking forward to the next release.

Shajith
This topic is locked and can not be replied to.