-3

I noticed both these methods for creating each loops in ruby on rails generate the exact same result.

What is the difference between doing the common array approach [] and the other ruby way %w()? (by the way, what is the real name for this second approach?)

Common Array

<% ['one', 'two', 'three', 'four', 'five'].each do |k| %>
    <div class="panel-<%= k %>">Panel <%= k.capitalize %></div>
<% end %>

Ruby

<% %w(one two three four five).each do |k| %>
    <div class="panel-<%= k %>">Panel <%= k.capitalize %></div>
<% end %>
gespinha
  • 7,968
  • 16
  • 57
  • 91

1 Answers1

0

Both are the same.

You can else try

%w[]

for creating array of strings. Consider this SO answer for further documentation

Community
  • 1
  • 1
Alex Antonov
  • 14,134
  • 7
  • 65
  • 142