Line breaks in YAML

K

Keith Carter

Sorry for all the YAML questions today!

Here is my YAML file-

foo:
this is a test
to see if ruby
recognizes line breaks

Here is my Ruby-

Loading development environment (Rails 2.0.2)
require 'yaml' => []
test = YAML::load_file("test.yml") => {"foo"=>"this is a test to see if ruby recognizes line breaks"}
puts test['foo']
this is a test to see if ruby recognizes line breaks
=> nil
Where'd the line breaks go?
 
T

Thomas Wieczorek

Shameless bumb. Stuck at work.

I've tried this in irb:

require 'yaml'

foo = "foo\nbar\nbaz"
y = YAML::dump(foo)
#=> "--- |-\nfoo\nbar\nbaz\n"
foz = YAML::load(y)
foo == foz #=> true

Not sure if that's what you meant.
 
K

Keith Carter

Thomas said:
Not sure if that's what you meant.

No, that's not quite it.

Really, what I'd like, is to be able to put multi-line Ruby code
snippets into a yml file.

For example, my yml file-

source_id:
a=2
b=2
if (a==b)
c=3
end

And my ruby-

Loading development environment (Rails 2.0.2)
require 'yaml' => []
test = YAML::load_file("test.yml") => {"source"=>"a=2 b=2 if (a==b) c=3 end"}
eval(test['source'])
SyntaxError: (eval):1:in `irb_binding': compile error
(eval):1: syntax error, unexpected tIDENTIFIER, expecting $end
a=2 b=2 if (a==b) c=3 end
^
from (irb):3
from (irb):3
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,244
Latest member
cryptotaxsoftware12

Latest Threads

Top