Sha256: 226cb5b5b0091c3c823ba81ea783a059fc766cef9a70f6260753ee2e650b952a

Contents?: true

Size: 336 Bytes

Versions: 4

Compression:

Stored size: 336 Bytes

Contents

# encoding: utf-8
class Array
  def to_list(separator: ', ', last_separator: separator, around: '"')
    items = self.map { |l| format("#{around}%s#{around}", l) }

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

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

    result
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.7.18 lib/fedux_org_stdlib/core_ext/array/list.rb
fedux_org-stdlib-0.7.17 lib/fedux_org_stdlib/core_ext/array/list.rb
fedux_org-stdlib-0.7.16 lib/fedux_org_stdlib/core_ext/array/list.rb
fedux_org-stdlib-0.7.15 lib/fedux_org_stdlib/core_ext/array/list.rb