Re: Problem with classes

Brian Candler <[email protected]> Wed, 10 Aug 2005 11:19:33 +0100
Newsgroups gmane.comp.apache.mod-ruby
Message-ID <[email protected]>
On Wed, Aug 10, 2005 at 11:11:13AM +0100, Brian Candler wrote:
> Strange. It works for me, both with and without the colons.

I don't understand why that didn't work for you, but I do have another
possible solution from http://www.modruby.net/doc/faq.en.html - put the
definitions for your class into a separate file and 'require' it. This
should ensure that the class is defined in the top-level namespace.

e.g.

  <% require 'test.rb' %>

  <html>
  <body>
  <% foo = Marshal.dump(Test.new()) %>
  <p><%= Marshal.load(foo).test %></p>
  </body>
  </html>

where test.rb contains

  class Test
    attr_reader :test
    def initialize
      @test = 5
    end
  end