Sha256: 561fa0dea3274baa416a44abe4df41142ed48373e7d770b59e7351dcd4a54bcc

Contents?: true

Size: 438 Bytes

Versions: 9

Compression:

Stored size: 438 Bytes

Contents

# encoding: UTF-8


module Spontaneous::Collections
  class HashWithFallback < Hash
    def initialize(fallback, use_fallback_proc, obj = nil, &block)
      use_fallback_proc ||= proc { |val| val.nil? }
      @fallback, @use_fallback_proc = fallback, use_fallback_proc
      super(obj, &block)
    end

    def [](key)
      val = super
      if @use_fallback_proc[val]
         val = @fallback[key]
      end
      val
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta10 lib/spontaneous/collections/hash_with_fallback.rb
spontaneous-0.2.0.beta9 lib/spontaneous/collections/hash_with_fallback.rb
spontaneous-0.2.0.beta8 lib/spontaneous/collections/hash_with_fallback.rb
spontaneous-0.2.0.beta7 lib/spontaneous/collections/hash_with_fallback.rb
spontaneous-0.2.0.beta6 lib/spontaneous/collections/hash_with_fallback.rb
spontaneous-0.2.0.beta5 lib/spontaneous/collections/hash_with_fallback.rb
spontaneous-0.2.0.beta4 lib/spontaneous/collections/hash_with_fallback.rb
spontaneous-0.2.0.beta3 lib/spontaneous/collections/hash_with_fallback.rb
spontaneous-0.2.0.beta2 lib/spontaneous/collections/hash_with_fallback.rb