Last Updated on November 30, 2019 by Christopher G Mendla
I had a situation where I wanted to pass a handful of objects to an .each do in Rails such as the points of the compass.
I didn’t find any useful documentation on how to do that. It dawned on me that I could probably set up a simple array and add the .each do to it.
Below is a sample of how this word work in a view.
<% [“North”, “East”, “South”, “West” ].each do |compass| %>
<%= compass %>
<% end %>
The results would be North East South West.
The usefulness of this is limited to those times when you have a small number of items that will not change.