Sha256: b2b663e61a02409d2e2b0af277d35d94126f3355bf233d1b3573bfdacebcf0f3

Contents?: true

Size: 564 Bytes

Versions: 142

Compression:

Stored size: 564 Bytes

Contents

# frozen_string_literal: true

# Responsible for decorating a collection which responds to `to_a` which will
# stringify all of the elements.
#
# Example
#
#     ArrayStringifier.new({a: 1, b: 2}).to_a # => [["a", "1"], ["b", "2"]]
#
class ArrayStringifier < SimpleDelegator
  alias_method :collection, :__getobj__

  def to_a
    stringify_items(collection.to_a)
  end

  private

  def stringify_items(collection)
    collection.map do |item|
      if item.respond_to?(:map)
        stringify_items(item)
      else
        item.to_s
      end
    end
  end
end

Version data entries

142 entries across 142 versions & 1 rubygems

Version Path
renalware-core-2.0.104 lib/array_stringifier.rb
renalware-core-2.0.103 lib/array_stringifier.rb
renalware-core-2.0.102 lib/array_stringifier.rb
renalware-core-2.0.101 lib/array_stringifier.rb
renalware-core-2.0.100 lib/array_stringifier.rb
renalware-core-2.0.99 lib/array_stringifier.rb
renalware-core-2.0.98 lib/array_stringifier.rb
renalware-core-2.0.97 lib/array_stringifier.rb
renalware-core-2.0.96 lib/array_stringifier.rb
renalware-core-2.0.95 lib/array_stringifier.rb
renalware-core-2.0.94 lib/array_stringifier.rb
renalware-core-2.0.93 lib/array_stringifier.rb
renalware-core-2.0.92 lib/array_stringifier.rb
renalware-core-2.0.91 lib/array_stringifier.rb
renalware-core-2.0.90 lib/array_stringifier.rb
renalware-core-2.0.89 lib/array_stringifier.rb
renalware-core-2.0.88 lib/array_stringifier.rb
renalware-core-2.0.87 lib/array_stringifier.rb
renalware-core-2.0.86 lib/array_stringifier.rb
renalware-core-2.0.85 lib/array_stringifier.rb