Sha256: ef7d1d288f2e987171ee7482fa74084ab3237581176369756678d2807e0bed45

Contents?: true

Size: 981 Bytes

Versions: 6

Compression:

Stored size: 981 Bytes

Contents

# encoding: utf-8
require 'fedux_org_stdlib/core_ext/array/list'

# Hash
class Hash
  # Convert Hash to list
  #
  # For more examples see 'fedux_org_stdlib/core_ext/array/list'
  #
  # @example Change separator for key and value
  #
  #   input = {
  #     opt1: 'asdf',
  #     opt2: 'asdf'
  #   }
  #
  #   input.to_list(format: "%s | %s")
  #   => "opt1 | asdf", "opt2 | asdf"
  #
  # @example Change separator between key/value-pairs
  #
  #   input = {
  #     opt1: 'asdf',
  #     opt2: 'asdf'
  #   }
  #
  #   input.to_list(format: "%s | %s")
  #   => "opt1 | asdf", "opt2 | asdf"
  #
  # @example Change character around key/value-pair
  #
  #   input = {
  #     opt1: 'asdf',
  #     opt2: 'asdf'
  #   }
  #
  #   input.to_list(around: "'")
  #   => 'opt1: asdf', 'opt2: asdf'
  #
  # @return [String]
  #   A string representation of hash as list
  def to_list(format: '%s: %s', **args)
    map { |key, value| format(format, key, value) }.to_list(**args)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.11.18 lib/fedux_org_stdlib/core_ext/hash/list.rb
fedux_org-stdlib-0.11.17 lib/fedux_org_stdlib/core_ext/hash/list.rb
fedux_org-stdlib-0.11.16 lib/fedux_org_stdlib/core_ext/hash/list.rb
fedux_org-stdlib-0.11.15 lib/fedux_org_stdlib/core_ext/hash/list.rb
fedux_org-stdlib-0.11.14 lib/fedux_org_stdlib/core_ext/hash/list.rb
fedux_org-stdlib-0.11.12 lib/fedux_org_stdlib/core_ext/hash/list.rb