From: Mark Hubbart Date: 2004-09-11T02:30:16+09:00 Subject: Re: methods in eruby On Sep 10, 2004, at 5:00 AM, Florian Weber wrote: > hi! > > is there some way to make this work: > > <% def foo %> > some stuff which should be displayed > <% end %> > .. > <%= foo %> > > ? First problem: in your example, foo doesn't return a string. It would try to print "some stuff which..." to whatever output is being used (on a webserver, the socket). So using <%= tags aren't nessesary. Second problem: because of the way that output is managed, the scope inside foo() can't see the output handler. Therefore, you get an error. Solution: ####### code: -- define foo <% foo = lambda do %> some stuff which should be displayed <% end %> -- now, test foo: <% foo.call %> -- test foo again: <% foo[] %> ####### output: -- define foo -- now, test foo: some stuff which should be displayed -- test foo again: some stuff which should be displayed > thanks! > > ciao! > florian cheers, Mark