Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/rspec_n/helpers/core_ext/array.rb
Instance Method Summary collapse
- #to_sentence(word_connector: ", ", two_word_connector: " or ", last_word_connector: " or ") ⇒ Object
Instance Method Details
#to_sentence(word_connector: ", ", two_word_connector: " or ", last_word_connector: " or ") ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/rspec_n/helpers/core_ext/array.rb', line 2 def to_sentence(word_connector: ", ", two_word_connector: " or ", last_word_connector: " or ") case length when 0 "" when 1 self[0].to_s.dup when 2 "#{self[0]}#{two_word_connector}#{self[1]}" else "#{self[0...-1].join(word_connector)}#{last_word_connector}#{self[-1]}" end end |