This post originated from an RSS feed registered with Ruby Buzz
by Jay Fields.
Original Post: Rails: Array#to_sentence
Feed Title: Jay Fields Thoughts
Feed URL: http://feeds.feedburner.com/jayfields/mjKQ
Feed Description: Blog about Ruby, Agile, Testing and other topics related to software development.
Converts the array to comma-seperated sentence where the last element is joined by the connector word. Options:
:connector: The word used to join the last element in arrays with two or more elements (default: "and")
:skip_last_comma: Set to true to return "a, b and c" instead of "a, b, and c".
Usage Array#to_sentence is perfect for joining information stored in an array that needs to be presented in a human readable format (e.g. an array of errors).