Class: Array Private
- Defined in:
- extend/array.rb,
extend/blank.rb,
extend/object/deep_dup.rb,
extend/array.rbi
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
Direct Known Subclasses
Instance Method Summary collapse
-
#blank? ⇒ Boolean
private
An array is blank if it's empty:.
-
#deep_dup ⇒ T.self_type
private
Returns a deep copy of array.
-
#fifth ⇒ Elem?
private
Equal to
self[4]
. -
#fourth ⇒ Elem?
private
Equal to
self[3]
. - #present? ⇒ Boolean private
-
#second ⇒ Elem?
private
Equal to
self[1]
. -
#third ⇒ Elem?
private
Equal to
self[2]
. -
#to_sentence(words_connector: ", ", two_words_connector: " and ", last_word_connector: " and ") ⇒ String
private
Converts the array to a comma-separated sentence where the last element is joined by the connector word.
Instance Method Details
#blank? ⇒ Boolean
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.
An array is blank if it's empty:
[].blank? # => true
[1,2,3].blank? # => false
99 |
# File 'extend/blank.rb', line 99 def blank? = empty? |
#deep_dup ⇒ T.self_type
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.
Returns a deep copy of array.
array = [1, [2, 3]] dup = array.deep_dup dup[1][2] = 4
array[1][2] # => nil dup[1][2] # => 4
32 33 34 |
# File 'extend/object/deep_dup.rb', line 32 def deep_dup T.unsafe(self).map(&:deep_dup) end |
#fifth ⇒ Elem?
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.
Equal to self[4]
.
Example
%w( a b c d e ).fifth # => "e"
39 |
# File 'extend/array.rb', line 39 def fifth = self[4] |
#fourth ⇒ Elem?
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.
Equal to self[3]
.
Example
%w( a b c d e ).fourth # => "d"
30 |
# File 'extend/array.rb', line 30 def fourth = self[3] |
#present? ⇒ Boolean
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.
102 |
# File 'extend/blank.rb', line 102 def present? = !empty? # :nodoc: |
#second ⇒ Elem?
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.
Equal to self[1]
.
Example
%w( a b c d e ).second # => "b"
12 |
# File 'extend/array.rb', line 12 def second = self[1] |
#third ⇒ Elem?
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.
Equal to self[2]
.
Example
%w( a b c d e ).third # => "c"
21 |
# File 'extend/array.rb', line 21 def third = self[2] |
#to_sentence(words_connector: ", ", two_words_connector: " and ", last_word_connector: " 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.
Converts the array to a comma-separated sentence where the last element is joined by the connector word.
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(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"
Copyright (c) David Heinemeier Hansson
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense and/or sell copies of the Software and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'extend/array.rb', line 93 def to_sentence(words_connector: ", ", two_words_connector: " and ", last_word_connector: " and ") case length when 0 +"" when 1 # This is not typesafe, if the array contains a BasicObject +T.unsafe(self[0]).to_s when 2 "#{self[0]}#{two_words_connector}#{self[1]}" else "#{T.must(self[0...-1]).join(words_connector)}#{last_word_connector}#{self[-1]}" end end |