Class: Array

Inherits:
Object show all
Defined in:
lib/jun/active_support/core_ext/array/access.rb,
lib/jun/active_support/core_ext/array/conversion.rb

Instance Method Summary collapse

Instance Method Details

#fifthObject



16
17
18
# File 'lib/jun/active_support/core_ext/array/access.rb', line 16

def fifth
  self[4]
end

#fourthObject



12
13
14
# File 'lib/jun/active_support/core_ext/array/access.rb', line 12

def fourth
  self[3]
end

#secondObject



4
5
6
# File 'lib/jun/active_support/core_ext/array/access.rb', line 4

def second
  self[1]
end

#second_to_lastObject



24
25
26
# File 'lib/jun/active_support/core_ext/array/access.rb', line 24

def second_to_last
  self[-2]
end

#thirdObject



8
9
10
# File 'lib/jun/active_support/core_ext/array/access.rb', line 8

def third
  self[2]
end

#third_to_lastObject



20
21
22
# File 'lib/jun/active_support/core_ext/array/access.rb', line 20

def third_to_last
  self[-3]
end

#to_sentence(delimiter: ", ", last_delimiter: "and") ⇒ Object



4
5
6
7
8
9
# File 'lib/jun/active_support/core_ext/array/conversion.rb', line 4

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