2007/8/7, Ronald Fischer <ronald.fischer / venyon.com>:
> > You would have to also explain how embedded control characters will be
> > printed because there is no way I know of at the moment that would
> > allow to embed e.g. a newline in a single quote string:
>
> Good point. I overlooked this. But there are easy workarounds. For
> example,
> pretty_inspectq could revert to double quotation if the string to be
> printed
> can not be formatted using single quotes. Or (remember that I don't want
> to change the default behaviour of pretty_inspect) an exception is
> thrown in
> this case, which makes sense: The user requests pretty_inspecting in
> single
> quotes, but if it is not possible, we should blame the user.
>
> > If you introduce a new syntax
>
> Certainly not! I don't want to open *that* can of worms.
>
> > 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.

> 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.  :-) You could use YAML or XML
for this although I believe you will find XML too verbose. :-)

Kind regards

robert