From: James Edward Gray II Date: 2004-10-28T03:50:22+09:00 Subject: Re: Learning erb On Oct 27, 2004, at 7:39 AM, Gavin Kistner wrote: > require 'erb' > erb = ERB.new <

Hello, World

> >

I like cheese because:

>
    > <% > reasons = [ "It's bad for me", "It is tasty", "And so yes" ] > reasons.each{ |reason| > puts "\t
  1. #{reason}
  2. " > } > %> >
> Done. > ENDERB > > puts erb.result( binding ) > > Er...in fact, the above doesn't run at all, oddly. > tmp.rb:12: undefined local variable or method `reason' for > main:Object (NameError) It works in standalone erb (with disjointed printing, of course), which is what ultimately led me to the error. The problem is your heredoc. It's trying to substitute #{reason}, before it ever makes it to to the ERB object. To fix, change: > erb = ERB.new <