Sha256: 8b6441b274d3f6e7faadd80cc6915a6688b54d8e9da7cce239a10aae8fa67bbd

Contents?: true

Size: 395 Bytes

Versions: 16

Compression:

Stored size: 395 Bytes

Contents

# frozen_string_literal: true
# encoding: utf-8

class UsingHash < Hash
  def use(key)
    wrap(self[key]).tap do
      delete(key)
    end
  end

  def use!(key)
    wrap(fetch(key)).tap do
      delete(key)
    end
  end

  private

  def wrap(v)
    case v
    when Hash
      self.class[v]
    when Array
      v.map do |subv|
        wrap(subv)
      end
    else
      v
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
mongo-2.16.4 spec/support/using_hash.rb
mongo-2.17.4 spec/support/using_hash.rb
mongo-2.18.3 spec/support/using_hash.rb
mongo-2.18.2 spec/support/using_hash.rb
mongo-2.17.3 spec/support/using_hash.rb
mongo-2.18.1 spec/support/using_hash.rb
mongo-2.18.0 spec/support/using_hash.rb
mongo-2.17.2 spec/support/using_hash.rb
mongo-2.16.3 spec/support/using_hash.rb
mongo-2.18.0.beta1 spec/support/using_hash.rb
mongo-2.16.2 spec/support/using_hash.rb
mongo-2.17.1 spec/support/using_hash.rb
mongo-2.16.1 spec/support/using_hash.rb
mongo-2.17.0 spec/support/using_hash.rb
mongo-2.16.0 spec/support/using_hash.rb
mongo-2.16.0.alpha1 spec/support/using_hash.rb