blob: 19220da2b1e82a56a60bd6d7816c8e868a937eba (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
module ActiveSupport #:nodoc:
module CoreExtensions #:nodoc:
module Array #:nodoc:
# Enables to conversion of Arrays to human readable lists. ['one', 'two', 'three'] => "one, two, and three"
module Conversions
# Converts the array to comma-seperated sentence where the last element is joined by the connector word (default is 'and').
def to_sentence(connector = 'and')
if length > 1
"#{self[0...-1].join(', ')}, #{connector} #{self[-1]}"
elsif length == 1
self[0]
end
end
# When an array is given to url_for, it is converted to a slash separated string.
def to_param
join '/'
end
end
end
end
end
|