Skip to content

Instantly share code, notes, and snippets.

@marvin
Created July 11, 2011 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marvin/1075455 to your computer and use it in GitHub Desktop.
Save marvin/1075455 to your computer and use it in GitHub Desktop.
ruby to_sentence configurations
>> %w(lorem ipsum dolor sit).to_sentence
=> "lorem, ipsum, dolor, and sit"
>> %w(lorem ipsum dolor sit).to_sentence(:words_connector => ' + ')
=> "lorem + ipsum + dolor, and sit"
>> %w(lorem ipsum).to_sentence(:two_words_connector => ' through ')
=> "lorem through ipsum"
# No effect if more than two words
>> %w(lorem ipsum dolor sit).to_sentence(:two_words_connector => ' through ')
=> "lorem, ipsum, dolor, and sit"
>> %w(lorem ipsum dolor sit).to_sentence(:last_word_connector => ' or ')
=> "lorem, ipsum, dolor or sit"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment