Html output from required file

Can someone please tell me why this doesn't work?

contents of test.rb

···

-------------------------
class Test
  def draw
    %> <b>draw method!</b> <%
  end
end

contents of test.rhtml
----------------------------
<%
require "test.rb"
Test.new.draw
%>

when Test class is in the same file it works but when it is 'require'd
I get errors.
Thanks for any tip

mark napsal(a):

Can someone please tell me why this doesn't work?

contents of test.rb
-------------------------
class Test
  def draw
    %> <b>draw method!</b> <%
  end
end

contents of test.rhtml
----------------------------
<%
require "test.rb"
Test.new.draw
%>

when Test class is in the same file it works but when it is 'require'd
I get errors.
Thanks for any tip

Perhaps because it's not supposed to work? "Require" is _not_ a textual include, it is equivalent to running the file through the Ruby parser, compiling methods into AST and adding these mthods into Ruby "object dictionary". The Ruby parser doesn't understand those "%>","<%"-tags you are using in your test.rb file. :wink:

Do you have any special intent, trying to perform output this way? I suppose it's not necessary at all.

Jakub

Hi,
Yes, I want my class to be able to output html without a bunch of ugly
'puts' lines.
I guess I'm looking for a way to have eruby handle the required file
instead of ruby.

Any help is appreciated.

I guess I just answered my own question. I should have been using
ERuby.import
d'oh!