Sha256: 5e14cc62bd6f684138359878f3af898c8655600eea07ed7e1a88b028226cb4e4

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

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

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

    # ==== Parameters
    # value<Object>:: Value to add to set.
    #
    # ==== Returns
    # true
    def <<(value)
      self[value] = true
    end

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

    # ==== Returns
    # 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

1 entries across 1 versions & 1 rubygems

Version Path
merb-core-0.9.3 lib/merb-core/core_ext/set.rb