I need to use $bar instead of bar to get it going…
@bar will do it, too, and that’s maybe the best way to do it.
[Other poster suggests passing binding.]
I have always wondered why erb does not provide in addition the
possibility to pass a regular hash. In general I don’t want to design
my objects or scopes around a template. Is there a rationale behind
that?
That helps (although I don’t understand it yet, but I’ll find out),
thanks!
ERb templates are resolved in the scope of some “binding”. They have
access to the variables in that binding. There is a private method
on Object (universally available) called binding(), which just
returns a Binding object for the current scope. By handing that to
ERb, you can control what it can access.
I have always wondered why erb does not provide in addition the
possibility to pass a regular hash. In general I don’t want to
design my objects or scopes around a template. Is there a rationale
behind that?
I imagine the reason is because ERb uses eval() under the hood and
the tool eval() gives us is Binding. We should be able to use that
to do pretty much what you want though: