methods in eruby

F

Florian Weber

hi!

is there some way to make this work:

<% def foo %>
some stuff which should be displayed
<% end %>
..
<%= foo %>

?

thanks!

ciao!
florian
 
M

Mark Hubbart

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
 
A

Alexey Verkhovsky

<% foo = lambda do %>
Oh... I was wondering about the same question, thanks a lot for the
answer.

Isn't lambda a deprecated keyword, by the way? I remember reading
something like that on this list.

Brgds,
Alex
 
M

Mikael Brockman

Kent Sibilev said:
No, it's proc keyword which is deprecated.

To be utterly pedantic, proc and lambda aren't keywords: they're
regular method names.
 
M

Mark Hubbart

Kernel#proc is deprecated, because it is different from Proc.new, which
causes confusion. Kernel#proc is an alias (effectively, if not
actually) for Kernel#lambda. The exact differences have been discussed
elsewhere on the list.
To be utterly pedantic, proc and lambda aren't keywords: they're
regular method names.

:)

cheers,
Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Problem with Apache 2 and eRubis/eRuby 1
Ubuntu/Apache/Eruby 1
mod_ruby, eRuby Question 3
eruby and caching 0
eRuby questions 5
eruby? 2
Problems- eruby and apache 1
eRuby giving problems with http.rb 7

Members online

Forum statistics

Threads
474,159
Messages
2,570,883
Members
47,415
Latest member
SharonCran

Latest Threads

Top