Module: Utils::Text Private

Defined in:
utils/text.rb

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Class Method Summary collapse

Class Method Details

.to_sentence(values, conjunction: "and") ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • values (Array<T.type_parameter(:Elem)>)
  • conjunction (String) (defaults to: "and")

Returns:



14
15
16
17
18
19
20
21
22
23
24
25
# File 'utils/text.rb', line 14

def to_sentence(values, conjunction: "and")
  case values.length
  when 0
    +""
  when 1
    +T.unsafe(values[0]).to_s
  when 2
    "#{values[0]} #{conjunction} #{values[1]}"
  else
    "#{T.must(values[0...-1]).join(", ")} #{conjunction} #{values[-1]}"
  end
end