Comma Separated List of Array – Good idea for Ruby on Rails?

I feel like there should be a rails function for doing a comma separated list from an array. Here’s how to do it explicitly:

<% search_tags.each_with_index do |tag, index| %>
  <% if index < search_tags.size - 1 %>
    <%= "#{tag}, " %>
  <% else %>
    <%= "#{tag}" %>
  <% end %>
<% end %>

…maybe `render_comma_separated_list(array)` or something.

An example array would like this = [“one”, “two”, “three”]

render_comma_separated_list(array)

=> one, two, three

Does something like this exist already?

Is this worth the effort of making a PR to Ruby on Rails?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.