Rails method for concatenation
3 answers
Rails provides a to_sentence
helper:
> ['a', 'b'].to_sentence
=> "a and b"
> ['a', 'b', 'c'].to_sentence
=> "a, b, and c"
If you want a, b and c
rather than a, b, and c
, you can change last_word_connector
:
> ['a', 'b', 'c'].to_sentence(last_word_connector: " and ")
=> "a, b and c"
+7
source to share