Class: Extlib::SimpleSet
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
- #<<(value) ⇒ TrueClass
-
#initialize(arr = []) ⇒ Array
constructor
The array the Set was initialized with.
-
#inspect ⇒ String
A human readable version of the set.
-
#merge(arr) ⇒ SimpleSet
The set after the Array was merged in.
Methods inherited from Hash
#add_html_class!, #environmentize_keys!, #except, from_xml, #only, #protect_keys!, #to_mash, #to_params, #to_xml_attributes, #unprotect_keys!
Constructor Details
#initialize(arr = []) ⇒ Array
Returns The array the Set was initialized with.
12 13 14 |
# File 'lib/extlib/simple_set.rb', line 12 def initialize(arr = []) arr.each {|x| self[x] = true} end |
Instance Method Details
#<<(value) ⇒ TrueClass
19 20 21 |
# File 'lib/extlib/simple_set.rb', line 19 def <<(value) self[value] = true end |
#inspect ⇒ String
Returns A human readable version of the set.
31 32 33 |
# File '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.
26 27 28 |
# File 'lib/extlib/simple_set.rb', line 26 def merge(arr) super(arr.inject({}) {|s,x| s[x] = true; s }) end |