Sha256: 00a873cbf86c8e05b63d62fe883c3bf9fd20569ade17daecd0e0e09c08f3fa98

Contents?: true

Size: 941 Bytes

Versions: 17

Compression:

Stored size: 941 Bytes

Contents

module Extlib
  # Simple set implementation
  # on top of Hash with merging support.
  #
  # In particular this is used to store
  # a set of callable actions of controller.
  class SimpleSet < Hash

    # @param arr<Array> Initial set values.
    #
    # @return <Array> The array the Set was initialized with
    def initialize(arr = [])
      arr.each {|x| self[x] = true}
    end

    # @param value<Object> Value to add to set.
    #
    # @return <TrueClass>
    def <<(value)
      self[value] = true
    end

    # @param arr<Array> Values to merge with set.
    #
    # @return <SimpleSet> The set after the Array was merged in.
    def merge(arr)
      super(arr.inject({}) {|s,x| s[x] = true; s })
    end

    # @return <String> A human readable version of the set.
    def inspect
      "#<SimpleSet: {#{keys.map {|x| x.inspect}.join(", ")}}>"
    end

    # def to_a
    alias_method :to_a, :keys

  end # SimpleSet
end # Merb

Version data entries

17 entries across 17 versions & 4 rubygems

Version Path
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/extlib-0.9.8/lib/extlib/simple_set.rb
merb-core-1.1.2 spec10/public/webrat/test_app/gems/gems/extlib-0.9.8/lib/extlib/simple_set.rb
merb-core-1.1.1 spec10/public/webrat/test_app/gems/gems/extlib-0.9.8/lib/extlib/simple_set.rb
merb-core-1.1.0 spec10/public/webrat/test_app/gems/gems/extlib-0.9.8/lib/extlib/simple_set.rb
merb-core-1.1.0.rc1 spec10/public/webrat/test_app/gems/gems/extlib-0.9.8/lib/extlib/simple_set.rb
merb-core-1.1.0.pre spec10/public/webrat/test_app/gems/gems/extlib-0.9.8/lib/extlib/simple_set.rb
extlib-0.9.8 lib/extlib/simple_set.rb
extlib-0.9.5 lib/extlib/simple_set.rb
extlib-0.9.6 lib/extlib/simple_set.rb
extlib-0.9.7 lib/extlib/simple_set.rb
extlib-0.9.4 lib/extlib/simple_set.rb
mack-facets-0.8.2 lib/gems/extlib-0.9.8/lib/extlib/simple_set.rb
thorero-0.9.4 lib/extlib/simple_set.rb
thorero-0.9.4.1 lib/extlib/simple_set.rb
thorero-0.9.4.4 lib/extlib/simple_set.rb
thorero-0.9.4.3 lib/extlib/simple_set.rb
thorero-0.9.4.2 lib/extlib/simple_set.rb