Sha256: 816de66a15b4b7c0ad186278096ca529ce83b0260f52efab07c7a1def19b415b

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

require 'celluloid'

module Celluloid
  module Extras

    # Concurrent Hash mirroring the existing Hash API as an Actor.
    class Hash
      include Celluloid

      def initialize starter={}
        @outer = starter
      end

      def [](k)
        @outer[k]
      end

      def []=(k,v)
        @outer.store(k, v)
        return v
      end

      def has_key?(k)
        @outer.has_key?(k)
      end

      def inspect
        @outer.inspect
      end

      def insert(k,v)
        @outer[k] = v
      end

      def merge(h)
        @outer.merge(h)
      end

      def merge!(h)
        @outer.merge!(h)
      end

      def delete(k)
        @outer.delete(k)
      end

      def each(&b)
        @outer.each(&b)
      end

      def sort_by(&b)
        @outer.sort_by(&b)
      end

      def inject(s=nil, &b)
        @outer.inject(s, &b)
      end

      def select!(&b)
        @outer.select!(&b)
      end

      def select(&b)
        @outer.select(&b)
      end

      def replace(h)
        @outer.replace(h)
      end

      def empty?
        @outer.count == 0
      end

      def any?
        @outer.any?
      end

      def count
        @outer.count
      end

      def keys
        @outer.keys
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
celluloid-extras-0.1.1 lib/celluloid/extras/hash.rb
celluloid-extras-0.1.0 lib/celluloid/extras/hash.rb