0

Say I wish to print the current directory as a list. The recommended method of doing this in the 3 books I've looked at is

<ul>
<% for file in Dir.glob('*') %>
   <li><%= file %> <li/>
<% end %>
</ul>

I think this looks rather clumsy. I'd like to do something like

<ul>
<%
   for file in Dir.glob('*')
      xxx "<li>" + file + "<li/>"
   end
%>
</ul>

What I'd like to know is what xxx is called. What I'd like to avoid is having lots of <% and %> all over the place.

cup
  • 7,589
  • 4
  • 19
  • 42
  • You are looking for `concat` – Uri Agassi May 27 '14 at 19:51
  • @UriAgassi Should we reopen the question ? I think although it is duplicate, but the improvement can be suggested in the comment itself. – Arup Rakshit May 27 '14 at 19:53
  • @UriAgassi Ok.. I agree – Arup Rakshit May 27 '14 at 19:55
  • I'll rephrase the question – cup May 27 '14 at 19:55
  • 1
    @cup - what you ask for is kind of counter to the whole purpose of ERB (which means _embedded_ ruby...), but the answers in the question we are pointing you to solve the problem you are referring to - `xxx` is `concat`... – Uri Agassi May 27 '14 at 20:00
  • If you want to avoid a lot of the `<%= ... %>` jazz, you could try a meta-markup like [HAML](http://haml.info/) that largely bypasses all of this. Additionally, as a matter of Ruby style, `for` is hardly ever used. That would be better written as `Dir.glob('*').each do |file|` – tadman May 27 '14 at 20:32

0 Answers0