Class: Array
- Defined in:
- lib/jun/active_support/core_ext/array/access.rb,
lib/jun/active_support/core_ext/array/conversion.rb
Instance Method Summary collapse
-
#fifth ⇒ Object
Returns the fifth element in the array.
-
#fourth ⇒ Object
Returns the fourth element in the array.
-
#second ⇒ Object
Returns the second element in the array.
-
#second_to_last ⇒ Object
Returns the second-to-last element in the array.
-
#third ⇒ Object
Returns the third element in the array.
-
#third_to_last ⇒ Object
Returns the third-to-last element in the array.
-
#to_sentence(delimiter: ", ", last_delimiter: "and") ⇒ Object
Converts the array to a comma-separated sentence.
Instance Method Details
#fifth ⇒ Object
Returns the fifth element in the array.
20 21 22 |
# File 'lib/jun/active_support/core_ext/array/access.rb', line 20 def fifth self[4] end |
#fourth ⇒ Object
Returns the fourth element in the array.
15 16 17 |
# File 'lib/jun/active_support/core_ext/array/access.rb', line 15 def fourth self[3] end |
#second ⇒ Object
Returns the second element in the array.
5 6 7 |
# File 'lib/jun/active_support/core_ext/array/access.rb', line 5 def second self[1] end |
#second_to_last ⇒ Object
Returns the second-to-last element in the array.
30 31 32 |
# File 'lib/jun/active_support/core_ext/array/access.rb', line 30 def second_to_last self[-2] end |
#third ⇒ Object
Returns the third element in the array.
10 11 12 |
# File 'lib/jun/active_support/core_ext/array/access.rb', line 10 def third self[2] end |
#third_to_last ⇒ Object
Returns the third-to-last element in the array.
25 26 27 |
# File 'lib/jun/active_support/core_ext/array/access.rb', line 25 def third_to_last self[-3] end |
#to_sentence(delimiter: ", ", last_delimiter: "and") ⇒ Object
Converts the array to a comma-separated sentence.
["one", "two", "three"].to_sentence #=> "one, two and three"
["left", "right"].to_sentence(last_delimiter: "or") #=> "left or right"
[].to_sentence #=> ""
12 13 14 15 16 17 |
# File 'lib/jun/active_support/core_ext/array/conversion.rb', line 12 def to_sentence(delimiter: ", ", last_delimiter: "and") return "" if none? return self.first if one? "#{self[0...-1].join(delimiter)} #{last_delimiter} #{self[-1]}" end |