Re: Problem with classes

Brian Candler <[email protected]> Wed, 10 Aug 2005 11:11:13 +0100
Newsgroups gmane.comp.apache.mod-ruby
Message-ID <[email protected]>
On Wed, Aug 10, 2005 at 11:47:34AM +0200, Andi Scharfstein wrote:
> So I can't reference my class properly, and the code stops working.
> BTW, trying to compile it from the command line doesn't work, either:
> 
>   # eruby test3.html
>   test3.html:6: compile error (SyntaxError)
>   test3.html:1: parse error
>    class ::Test
>            ^
>   test3.html:6: parse error

Strange. It works for me, both with and without the colons.

# cat test.rhtml
  <%
  class ::Test
    attr_reader :test
    def initialize
      @test = 5
    end
  end
  %>

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

  <html>
  <body>
  
  <p>5</p>
  </body>
  </html>

It works with 'erb' too. This is with:

eruby-1.0.5         Interprets Ruby code embedded in a text file like PHP/ePerl
ruby-1.8.2_3        An object-oriented interpreted scripting language

installed from FreeBSD ports.

Regards,

Brian.