Methods in eruby

hi!

is there some way to make this work:

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

?

thanks!

ciao!
florian

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

···

On Sep 10, 2004, at 5:00 AM, Florian Weber wrote:

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

···

On Fri, 2004-09-10 at 20:30, Mark Hubbart wrote:

<% foo = lambda do %>

No, it's proc keyword which is deprecated.

Cheers,
Kent.

···

On Sep 10, 2004, at 5:38 PM, Alexey Verkhovsky wrote:

On Fri, 2004-09-10 at 20:30, Mark Hubbart wrote:

<% 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

Kent Sibilev <ksibilev@bellsouth.net> writes:

···

On Sep 10, 2004, at 5:38 PM, Alexey Verkhovsky wrote:
> On Fri, 2004-09-10 at 20:30, Mark Hubbart wrote:
>> <% 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.

No, it's proc keyword which is deprecated.

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

Kent Sibilev <ksibilev@bellsouth.net> writes:

<% 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.

No, it's proc keyword which is deprecated.

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.

:slight_smile:

cheers,
Mark

···

On Sep 10, 2004, at 3:07 PM, Mikael Brockman wrote:

On Sep 10, 2004, at 5:38 PM, Alexey Verkhovsky wrote:

On Fri, 2004-09-10 at 20:30, Mark Hubbart wrote: