G
Gaspard Bucher
Hi !
I found some solutions to create recursion in erb templates.
What do you think of these solutions ? What problems could there be ?
I have a small preference for the first solution since it keeps all
the context available inside the "lambda".
Solution 1:
<% a = lambda do |var| %>
hello '<%= var %>'
<% end %>
-------------
<% a.call('baba') %>
<% a.call(man) %>
Solution 2:
<% def a_fun(var); _erbout = ''; %>
hello again, '<%= var %>'
<% end %>
-------------
<%= a_fun('baba') %>
<%= a_fun(man) %>
Thanks for your comments !
Gaspard
I found some solutions to create recursion in erb templates.
What do you think of these solutions ? What problems could there be ?
I have a small preference for the first solution since it keeps all
the context available inside the "lambda".
Solution 1:
<% a = lambda do |var| %>
hello '<%= var %>'
<% end %>
-------------
<% a.call('baba') %>
<% a.call(man) %>
Solution 2:
<% def a_fun(var); _erbout = ''; %>
hello again, '<%= var %>'
<% end %>
-------------
<%= a_fun('baba') %>
<%= a_fun(man) %>
Thanks for your comments !
Gaspard