Class: Extlib::SimpleSet

Inherits:
Hash show all
Defined in:
lib/gems/extlib-0.9.8/lib/extlib/simple_set.rb

Overview

Simple set implementation on top of Hash with merging support.

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

Instance Method Summary collapse

Methods inherited from Hash

#&, #*, #+, #-, #add_html_class!, #alias!, #argumentize, autonew, #collate, #collate!, #delete_unless, #delete_values, #delete_values_at, #diff, #each_with_key, #environmentize_keys!, #except, #except!, from_xml, #has_keys?, #has_only_keys?, #insert, #inverse, #join, #mash!, #normalize_param, #only, #protect_keys!, #recursive_merge, #recursive_merge!, #recursively, #recursively!, #rekey, #rekey!, #replace_each, #restore_snapshot, #reverse_merge, #reverse_merge!, #select!, #slice, #slice!, #stringify_keys, #stringify_keys!, #swap!, #symbolize_keys, #symbolize_keys!, #take_snapshot, #to_h, #to_mash, #to_openobject, #to_ostruct, #to_ostruct_recurse, #to_params, #to_proc, #to_proc_with_reponse, #to_shell, #to_shellwords, #to_struct, #to_xml, #to_xml_attributes, #traverse, #traverse!, #unprotect_keys!, #update_each, #update_keys, #update_values, #weave, zipnew, #|

Methods included from Random

append_features

Methods included from URI::Hash

#to_uri

Constructor Details

#initialize(arr = []) ⇒ Array

Returns The array the Set was initialized with.

Parameters:

  • arr (Array) (defaults to: [])

    Initial set values.



12
13
14
# File 'lib/gems/extlib-0.9.8/lib/extlib/simple_set.rb', line 12

def initialize(arr = [])
  arr.each {|x| self[x] = true}
end

Instance Method Details

#<<(value) ⇒ TrueClass

Parameters:

  • value (Object)

    Value to add to set.

Returns:



19
20
21
# File 'lib/gems/extlib-0.9.8/lib/extlib/simple_set.rb', line 19

def <<(value)
  self[value] = true
end

#inspectString

Returns A human readable version of the set.

Returns:

  • (String)

    A human readable version of the set.



31
32
33
# File 'lib/gems/extlib-0.9.8/lib/extlib/simple_set.rb', line 31

def inspect
  "#<SimpleSet: {#{keys.map {|x| x.inspect}.join(", ")}}>"
end

#merge(arr) ⇒ SimpleSet

Returns The set after the Array was merged in.

Parameters:

  • arr (Array)

    Values to merge with set.

Returns:

  • (SimpleSet)

    The set after the Array was merged in.



26
27
28
# File 'lib/gems/extlib-0.9.8/lib/extlib/simple_set.rb', line 26

def merge(arr)
  super(arr.inject({}) {|s,x| s[x] = true; s })
end