sonic-pi
https://github.com/sonic-pi-net/sonic-pi
C++
Code. Music. Live.
Array#to_sentence
Converts the array to a comma-separated sentence where the last element is joined by the connector word. You can pass the following options to change the default behavior. If you pass an option key that doesn't exist in the list below, it will raise an <tt>ArgumentError</tt>. ==== Options * <tt>:words_connector</tt> - The sign or word used to join the elements in arrays with two or more elements (default: ", "). * <tt>:two_words_connector</tt> - The sign or word used to join the elements in arrays with two elements (default: " and "). * <tt>:last_word_connector</tt> - The sign or word used to join the last element in arrays with three or more elements (default: ", and "). * <tt>:locale</tt> - If +i18n+ is available, you can set a locale and use the connector options defined on the 'support.array' namespace in the corresponding dictionary file. ==== Examples [].to_sentence # => "" ['one'].to_sentence # => "one" ['one', 'two'].to_sentence # => "one and two" ['one', 'two', 'three'].to_sentence # => "one, two, and three" ['one', 'two'].to_sentence(passing: 'invalid option') # => ArgumentError: Unknown key :passing ['one', 'two'].to_sentence(two_words_connector: '-') # => "one-two" ['one', 'two', 'three'].to_sentence(words_connector: ' or ', last_word_connector: ' or at least ') # => "one or two or at least three" Using <tt>:locale</tt> option: # Given this locale dictionary: # # es: # support: # array: # words_connector: " o " # two_words_connector: " y " # last_word_connector: " o al menos " ['uno', 'dos'].to_sentence(locale: :es) # => "uno y dos" ['uno', 'dos', 'tres'].to_sentence(locale: :es) # => "uno o dos o al menos tres"
Edit
git clone [email protected]:sonic-pi-net/sonic-pi.git
cd sonic-pi
open app/server/ruby/vendor/activesupport-7.0.6/lib/active_support/core_ext/array/conversions.rb
Contribute
# Make a new branchgit checkout -b -your-name--update-docs-Array-to_sentence-for-pr
# Commit to gitgit add app/server/ruby/vendor/activesupport-7.0.6/lib/active_support/core_ext/array/conversions.rbgit commit -m "better docs for Array#to_sentence"
# Open pull requestgem install hub # on a mac you can `brew install hub`
hub fork
git push <your name> -your-name--update-docs-Array-to_sentence-for-pr
hub pull-request
# Celebrate!