2007/8/7, Ronald Fischer <ronald.fischer / venyon.com>:
> > > > Btw, there is another variant for switching between
> > single and double
> > > > quotes: you can use a global variable.  This has the
> > advantage that
> > > > you do not need to touch any #inspect implementation of
> > custom classes
> > > > - but comes at a price of course.
> > >
> > > Hmmmmm.... here I don't see the point.
> >
> > Global variables are generally considered bad OO and you should
> > normally try to avoid them if possible.
>
> You got me wrong here: I wanted to say that I don't see how globals
> would help me here.

The global would be the flag which quoting style to use.  Advantage is
that you do not need to pass it around (i.e. if YourClass#inspect has
some String members whose #inspect output it includes in its own
output).

> > > In my case, I use pretty_inspect to "marshal" Ruby data types (they
> > > are written to a file, which is then edited by the user, and finally
> > > eval'ed by another Ruby application). I use pretty_inspect to easily
> > > format Ruby structures (arrays...), but for the user, it is more
> > > convenient
> > > to use single quoted strings when editing the data, because he needs
> > > to care less about escaping rules.
> >
> > The proper way to do this would of course be a decent parser because
> > eval has serious security implications.
>
> Yes, security implications for instance. The user could arbitrarily ruin
> anything by inserting suitable statements. Only that in *this* case,
> security is a non-issue, but time to invest in the implementation is
> one. If I define the file format as "Ruby code", parsing is trivial,
> as it is done by Ruby; and creating the file is also trivial, using
> pretty_inspect.

Just wanted to make sure you are aware of the implications. If it's
not an issue, good.

Cheers

robert