Class Extlib::SimpleSet
In: lib/extlib/simple_set.rb
Parent: Hash
Hash SimpleSet ::String ByteArray StandardError InvalidResourceError Logger Pool lib/extlib/logger.rb lib/extlib/byte_array.rb lib/extlib/simple_set.rb Inflection ClassMethods Hook Assertions lib/extlib/pooling.rb Pooling Extlib dot/m_30_0.png

Simple set implementation on top of Hash with merging support.

In particular this is used to store a set of callable actions of controller.

Methods

<<   inspect   merge   new  

External Aliases

keys -> to_a
  def to_a

Public Class methods

Create a new SimpleSet containing the unique members of arr

@param [Array] arr Initial set values.

@return [Array] The array the Set was initialized with

@api public

[Source]

    # File lib/extlib/simple_set.rb, line 17
17:     def initialize(arr = [])
18:       Array(arr).each {|x| self[x] = true}
19:     end

Public Instance methods

Add a value to the set, and return it

@param [Object] value Value to add to set.

@return [SimpleSet] Receiver

@api public

[Source]

    # File lib/extlib/simple_set.rb, line 29
29:     def <<(value)
30:       self[value] = true
31:       self
32:     end

Get a human readable version of the set.

  s = SimpleSet.new([:a, :b, :c])
  s.inspect                 #=> "#<SimpleSet: {:c, :a, :b}>"

@return [String] A human readable version of the set.

@api public

[Source]

    # File lib/extlib/simple_set.rb, line 58
58:     def inspect
59:       "#<SimpleSet: {#{keys.map {|x| x.inspect}.join(", ")}}>"
60:     end

Merge arr with receiver, producing the union of receiver & arr

  s = Extlib::SimpleSet.new([:a, :b, :c])
  s.merge([:c, :d, :e, f])  #=> #<SimpleSet: {:e, :c, :f, :a, :d, :b}>

@param [Array] arr Values to merge with set.

@return [SimpleSet] The set after the Array was merged in.

@api public

[Source]

    # File lib/extlib/simple_set.rb, line 45
45:     def merge(arr)
46:       super(arr.inject({}) {|s,x| s[x] = true; s })
47:     end

[Validate]