Sha256: 674e54adb6325908f6f5ca7e78b32b2cdefaa5079386e5d7022410a75cc63092

Contents?: true

Size: 321 Bytes

Versions: 11

Compression:

Stored size: 321 Bytes

Contents

unless Struct.method_defined? :dig
  class Struct
    def dig(key, *rest)
      return nil unless respond_to?(key)
      val = public_send(key)
      return val if rest.empty? || val == nil
      raise TypeError, "#{val.class} does not have #dig method" unless val.respond_to? :dig
      val.dig(*rest)
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
backports-3.21.0 lib/backports/2.3.0/struct/dig.rb
backports-3.20.2 lib/backports/2.3.0/struct/dig.rb
backports-3.20.1 lib/backports/2.3.0/struct/dig.rb
backports-3.20.0 lib/backports/2.3.0/struct/dig.rb
backports-3.19.0 lib/backports/2.3.0/struct/dig.rb
backports-3.18.2 lib/backports/2.3.0/struct/dig.rb
backports-3.18.1 lib/backports/2.3.0/struct/dig.rb
backports-3.18.0 lib/backports/2.3.0/struct/dig.rb
backports-3.17.2 lib/backports/2.3.0/struct/dig.rb
backports-3.17.1 lib/backports/2.3.0/struct/dig.rb
backports-3.17.0 lib/backports/2.3.0/struct/dig.rb