Class: Extlib::SimpleSet

### Home Classes Methods

### In Files

- lib/extlib/simple_set.rb

### Parent

Hash

### Methods

- ::new
- #<<
- #inspect
- #merge

### Files

- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- Extlib
- Extlib::Assertions
- Extlib::ByteArray
- Extlib::Hook
- Extlib::Hook::ClassMethods
- Extlib::Inflection
- Extlib::LocalObjectSpace
- Extlib::Logger
- Extlib::Pooling
- Extlib::Pooling::InvalidResourceError
- Extlib::Pooling::Pool
- Extlib::SimpleSet
- Gem
- Gem::SourceIndex
- Gem::Specification
- LazyModule
- LazyModule::ClassMethods
- Array
- Class
- DateTime
- Dictionary
- FalseClass
- Hash
- LazyArray
- Mash
- Module
- NilClass
- Numeric
- Object
- ObjectSpace
- Pathname
- REXMLUtilityNode
- String
- Struct
- Symbol
- Time
- ToHashParser
- TrueClass
- VirtualFile

No matching classes.

# Extlib::SimpleSet

Simple set implementation on top of Hash with merging support.

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

### Public Class Methods

new(arr = []) click to toggle source

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

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

### Public Instance Methods

<<(value) click to toggle source

Add a value to the set, and return it

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

@return [SimpleSet] Receiver

@api public

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

inspect() click to toggle source

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

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

merge(arr) click to toggle source

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

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.