Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/fedux_org_stdlib/core_ext/array/list.rb

Overview

Array

Instance Method Summary collapse

Instance Method Details

#to_list(separator: ', ', last_separator: separator, around: '"') ⇒ String

Convert array to list

Returns:

  • (String)

    A string representation of list



8
9
10
11
12
13
14
15
16
17
# File 'lib/fedux_org_stdlib/core_ext/array/list.rb', line 8

def to_list(separator: ', ', last_separator: separator, around: '"')
  items = map { |l| format("#{around}%s#{around}", l) }

  return items.join(last_separator) if items.size <= 2

  result = items.slice(0..-2).join(separator) << last_separator
  result << items.last

  result
end