my_overflowed_stack
my_overflowed_stack

Reputation: 604

Using a global ruby variable inside YAML

Given the following YAML file:

---
foo: <%= $stdout %>

When I try to ERB this yaml file:

YAML.load(ERB.new(File.read(filename)).result)

I get the following result:

{"foo"=>nil}

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

Upvotes: 0

Views: 76

Answers (1)

David Grayson
David Grayson

Reputation: 87406

Look at what you get when you just run ERB:

ERB.new("foo: <%= $stdout %>").result

The result is this:

foo: #<IO:0x0056078694db38>

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

Upvotes: 2

Related Questions