Sha256: 1f62084b2eb83f9e45121549e20c71931e07e2e3a85a461901536e140f517a5a

Contents?: true

Size: 770 Bytes

Versions: 8

Compression:

Stored size: 770 Bytes

Contents

module Rumx
  module Beans
    class Hash
      include Bean

      def initialize(&block)
        raise 'Must be given initialize instance to create the bean' unless block_given?
        @block = block
        # Hacks for potential race conditions
        bean_children
        bean_synchronize {}
      end

      def [](key)
        child = bean_children[key]
        return child if child
        bean_synchronize do
          # Try it again to prevent race
          child = bean_children[key]
          return child if child
          child = @block.call(key)
          bean_add_child(key, child)
        end
        return child
      end

      def delete(key)
        bean_synchronize do
          bean_remove_child(key)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rumx-0.2.3 lib/rumx/beans/hash.rb
rumx-0.2.2 lib/rumx/beans/hash.rb
rumx-0.1.5 lib/rumx/beans/hash.rb
rumx-0.1.4 lib/rumx/beans/hash.rb
rumx-0.1.3 lib/rumx/beans/hash.rb
rumx-0.1.2 lib/rumx/beans/hash.rb
rumx-0.1.1 lib/rumx/beans/hash.rb
rumx-0.1.0 lib/rumx/beans/hash.rb