Erb on the Herb?

There seems to be some issue with the binding in ERB, any ideas?

(erb):16: undefined local variable or method `priority' for main:Object
(NameError)
from d:/utils/ruby/lib/ruby/1.8/erb.rb:739:in `value'
from d:/utils/ruby/lib/ruby/1.8/erb.rb:739:in `result'
from testerb.rb:36

is what I get when I try to run the following, taken from
http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/

require "erb"

# Create template.
template = %q{

···

From: James Edward Gray II <james@grayproductions.net>
To: <%= to %>
Subject: Addressing Needs

<%= to[/\w+/] %>:

Just wanted to send a quick note assuring that your needs are being
addressed.

I want you to know that my team will keep working on the issues,
especially:

<%# ignore numerous minor requests -- focus on priorities %>
% priorities.each do |priority|
* <%= priority %>
% end

Thanks for your patience.

James Edward Gray II
}.gsub(/^ /, '')

message = ERB.new(template, 0, "%<>")

# Set up template data.
to = "Community Spokesman <spokesman@ruby_community.org>"
priorities = [ "Run Ruby Quiz",
"Document Modules",
"Answer Questions on Ruby Talk" ]

# Produce result.
email = message.result
puts email

Lyndon Samson wrote:

There seems to be some issue with the binding in ERB, any ideas?
I want you to know that my team will keep working on the issues,
especially:

<%# ignore numerous minor requests -- focus on priorities %>
% priorities.each do |priority|

This line -^ is just some other output of ERB - there are no '<%' ... '%>' pairs...

* <%= priority %>
% end

Would this do it?

<% priorities.each do |priority| %>
* <%= priority %>
<% end %>

Hope that helped

Happy rubying

Stephan

There seems to be some issue with the binding in ERB, any ideas?

Works fine here. I pulled the code right out of your email and pasted it into a file:

Neo:~/Desktop$ ruby erb_test.rb

···

On Aug 18, 2005, at 2:21 AM, Lyndon Samson wrote:

From: James Edward Gray II <james@grayproductions.net>
To: Community Spokesman <spokesman@ruby_community.org>
Subject: Addressing Needs

Community:

Just wanted to send a quick note assuring that your needs are being
addressed.

I want you to know that my team will keep working on the issues,
especially:

* Run Ruby Quiz
* Document Modules
* Answer Questions on Ruby Talk

Thanks for your patience.

James Edward Gray II
Neo:~/Desktop$ ruby -v
ruby 1.8.2 (2004-12-25) [powerpc-darwin7.7.0]

I'm not sure what's going on.

James Edward Gray II

Stephan Kämper wrote:

% priorities.each do |priority|

This line -^ is just some other output of ERB - there are no '<%' ... '%>' pairs...

Not, according to the rdoc, when '%' is passed to ERB.new.

Devin

Works fine here. I pulled the code right out of your email and
pasted it into a file:

Hmm, it would be interesting if a few others could try it, it may be
something to do with my specific ruby environment.

D:\lcs\source\ruby>ruby -v
ruby 1.8.2 (2004-12-25) [i386-mswin32]

Lyndon Samson wrote:

Works fine here. I pulled the code right out of your email and
pasted it into a file:
   

Hmm, it would be interesting if a few others could try it, it may be something to do with my specific ruby environment.

D:\lcs\source\ruby>ruby -v
ruby 1.8.2 (2004-12-25) [i386-mswin32]

Works for me. Sorry!

C:\Documents and Settings\dlm>ruby -v
ruby 1.8.2 (2004-12-25) [i386-mswin32]

All I did was type "ruby", hit Enter, pasted in the code, hit Enter, hit Ctrl-D, and hit Enter.

Devin