Forum: Ruby Erb rdoc wrong?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
24499e811f19343c7dc406104e9b5785?d=identicon&s=25 Belorion (Guest)
on 2006-02-18 18:53
(Received via mailing list)
Greetings.

I am trying to use Erb to process a plain-text template.  Following the
RDoc
documentation at
http://www.ruby-doc.org/stdlib/libdoc/erb/rdoc/cla..., I can't
get
the first plain-text example to work.  ruby 1.8.2 (2004-12-25)
[i686-linux].  Below[1] is the actual sample script which isn't working
(it's not finding the local variables when processing the template).
Any
ideas what's going on here?  Thanks.

-Matt

[1]
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
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2006-02-18 19:11
(Received via mailing list)
On Feb 18, 2006, at 11:53 AM, Belorion wrote:

> Any ideas what's going on here?

Hmm, has ERB stopped defaulting to a top-level binding?

>   email = message.result

Change that to:

   email = message.result(binding)

Can someone please patch the docs for me?

James Edward Gray II
This topic is locked and can not be replied to.