I recall an old post by Why which described some way to inline chunks of
YAML right into Ruby code. Could not locate it in Google. Roughly like
def foo
a = %y
r: abc
s: pqr
t: - 1
- 2
- 3
%y
return a
end
Does anyone have the details, and what to include to enable this processing?
Conversely, is there any way to include Ruby code inline in YAML? Could "!!"
be faked out to accomplish this?
And lastly, could YAML be used in a re-entrant way e.g. could the code
processing a private type !! in the middle of a YAML::load in turn make a
nested call to YAML::load?
I recall an old post by Why which described some way to inline chunks of
YAML right into Ruby code. Could not locate it in Google. Roughly like
def foo
a = %y
r: abc
s: pqr
t: - 1
- 2
- 3
%y
return a
end
Does anyone have the details, and what to include to enable this processing?
you have to patch ruby and recompile
Conversely, is there any way to include Ruby code inline in YAML? Could "!!"
be faked out to accomplish this?
And lastly, could YAML be used in a re-entrant way e.g. could the code
processing a private type !! in the middle of a YAML::load in turn make a
nested call to YAML::load?
On a related note, I would like to see Ruby conform to YAML multipart document
system. Rough idea:
--- !!rubyscript
# blah blah blah
--- !!rubyscript/test
# tests
--- !!rubyscript/data
# instead of __DATA__
I'm sure this can be improved upon / thoughout more too.
T.
···
On Tuesday 26 October 2004 12:09 pm, Its Me wrote:
Conversely, is there any way to include Ruby code inline in YAML? Could
"!!" be faked out to accomplish this?
And lastly, could YAML be used in a re-entrant way e.g. could the code
processing a private type !! in the middle of a YAML::load in turn make a
nested call to YAML::load?
On Tuesday 26 October 2004 12:34 pm, gabriele renzi wrote:
Its Me ha scritto:
> I recall an old post by Why which described some way to inline chunks of
> YAML right into Ruby code. Could not locate it in Google. Roughly like
>
> def foo
> a = %y
> r: abc
> s: pqr
> t: - 1
> - 2
> - 3
> %y
> return a
> end
>
> Does anyone have the details, and what to include to enable this
> processing?
I recall an old post by Why which described some way to inline chunks of
YAML right into Ruby code. Could not locate it in Google. Roughly like
def foo
a = %y
r: abc
s: pqr
t: - 1
- 2
- 3
%y
return a
end
Does anyone have the details, and what to include to enable this processing?
you have to patch ruby and recompile
You can also use the source code filter technique described in [ruby-talk:116822], but you would need to implement the syntax for yourself. The benefit of this is that it will not need a recompile of Ruby.
I just wanted to add that if you find the courage to patch the Ruby source
and recompile it, be aware that the patch is not backward compatible with
current Ruby; it breaks a number of things, and changes some other things.
If you have some patience, I'll brew a version that can retain backward
compatibility at the price of lack of uniformity.
And if you want other people to use your code, you should go with
Florian's source code filter technique.
I just wanted to add that if you find the courage to patch the Ruby source
and recompile it, be aware that the patch is not backward compatible with
current Ruby; it breaks a number of things, and changes some other things.
Hmm.. that sort of makes it sound like it will bring down your whole system
I don't think its that bad. I've tried it and works rather well. Here are the
specific notes below. Is there more to it than these points? If no, then I
think it's pretty usable. Just be aware of following potential snags.
Notes: Patches the ruby source (v1.8.2, may work for other versions) such that
it allows to redefine the %-literals. The literals are enabled when passing
-% as option to the Ruby interpreter. This is done to enable Ruby to still
compile its extensions, since there are a number of backwards
incompatibilities incurred by this patch:
* %x becomes %X (%x still works but without escaping)
* %r becomes %R (ditto)
* The o option for %r is broken.
* %W is _terminally_ broken. Try %W{ hello\ world #{} }
and see what happens before & after.
* 'def %a' no longer means 'def %(a)'
* Cannot be called with a receiver
Nontheless, it is an expiremental patch. Do not use in production
environments!
If you have some patience, I'll brew a version that can retain backward
compatibility at the price of lack of uniformity.
I'd prefer the uniformity. I don't think %r and %x, nor def %a, are commonly
used enough to fuss about. /%r/%R/ is easy enough any way.