Class: Array
Overview
Instance Method Summary collapse
Instance Method Details
#to_sentence(words_connector: ', ', two_words_connector: ' and ', last_word_connector: ', and ') ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/dayone-kindle.rb', line 25 def to_sentence(words_connector: ', ', two_words_connector: ' and ', last_word_connector: ', and ') case length when 0 '' when 1 "#{self[0]}" when 2 "#{self[0]}#{two_words_connector}#{self[1]}" else "#{self[0...-1].join(words_connector)}#{last_word_connector}#{self[-1]}" end end |