Dave Thomas <Dave / PragmaticProgrammer.com> wrote:
>
>
>I'm looking for some inspiration.
>
>'ri' displays information about Ruby methods etc. It holds these
>descriptions in a set of marshaled objects, one per class or
>module. These marshaled objects ae prepared as I ship ri, using a
>simplified form of the XML used to generate the online book.
>
>Now, my problem is that marshaled classes are dependent on the Ruby
>version number: I'm writing the classes out using 1.6.2, and someone
>who's trying to use ri with 1.6.1 will get an error.
>
>So, ideally I'd like to construct these marshaled classes not when I
>generate the distribution at my end, but instead when I install it on
>a target machine.
>
>To do that with the current scheme would require that every client
>have the Ruby xmlparser module installed, which in turn requires Jim
>Clark's expat library. This seems onerous!
>
>So, I initially started hacking together yet another flat file
>representation of the data. I'd ship it with ri, and when you type
>'ruby install.rb', the installer would read it and generate the
>marshaled classes. Then that little alarm bell started ringing that
>said "there has to be a better way". Unfortunately, the battery ran
>down before it got around to telling me what that better way is.
>
>So, any ideas?

Yes.  Use ruby as your parser.

This is a trick I picked up in Perl from an old Lisp
hacker, write out your nested data structures as nicely
formatted code and you get a format that is both very
easy to parse and which most people find acceptable as
a configuration format.

To see what I mean, in Perl write a bit of code that
looks like this:

    use Data::Dumper;
    $Data::Dumper::Indent = 1;
    # Build up some complex data structure here...
    $data = [qw(an anonymous array for starters)];
    print Dumper $data;

Play around with the data structure a little and think
about how it looks.  You will probably be able to figure
out how to write your objects prettily to this data
structure about as easily as you can write to any
flatfile scheme you come up with, but with this one
parsing is trivial.

Cheers,
Ben
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com