Sha256: d948ee4b703635068b82fdc02a9af4323811426946ddc63293a120980a2e161d

Contents?: true

Size: 704 Bytes

Versions: 8

Compression:

Stored size: 704 Bytes

Contents

module Polyfill
  module V2_3
    module Array
      def dig(head, *rest)
        [head, *rest].reduce(self) do |value, accessor|
          next_value =
            case value
            when ::Array
              value.at(accessor)
            when ::Hash
              value[accessor]
            when ::Struct
              value[accessor] if value.members.include?(accessor)
            else
              begin
                break value.dig(*rest)
              rescue NoMethodError
                raise TypeError, "#{value.class} does not have a #dig method"
              end
            end

          break nil if next_value.nil?
          next_value
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
polyfill-1.2.0 lib/polyfill/v2_3/array.rb
polyfill-1.1.0 lib/polyfill/v2_3/array.rb
polyfill-1.0.1 lib/polyfill/v2_3/array.rb
polyfill-1.0.0 lib/polyfill/v2_3/array.rb
polyfill-0.10.0 lib/polyfill/v2_3/array.rb
polyfill-0.9.0 lib/polyfill/v2_3/array.rb
polyfill-0.8.0 lib/polyfill/v2_3/array.rb
polyfill-0.7.0 lib/polyfill/v2_3/array.rb