my_overflowed_stack my_overflowed_stack - 1 year ago 96
Ruby Question

Using a global ruby variable inside YAML

Given the following YAML file:

foo: <%= $stdout %>

When I try to ERB this yaml file:


I get the following result:


Why isn't
resolving correct? If I put other ruby code in there, it works as expected.

Answer Source

Look at what you get when you just run ERB:"foo: <%= $stdout %>").result

The result is this:

foo: #<IO:0x0056078694db38>

So foo will be set to nil because # is the comment character in YAML.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download