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) ⇒ SimpleSet
Add a value to the set, and return it.
-
#initialize(arr = []) ⇒ Array
constructor
Create a new SimpleSet containing the unique members of arr.
-
#inspect ⇒ String
Get a human readable version of the set.
-
#merge(arr) ⇒ SimpleSet
Merge arr with receiver, producing the union of receiver & arr.
Methods inherited from Hash
#add_html_class!, #environmentize_keys!, #except, from_xml, #normalize_param, #only, #protect_keys!, #to_mash, #to_params, #to_xml_attributes, #unprotect_keys!
Constructor Details
Instance Method Details
#<<(value) ⇒ SimpleSet
Add a value to the set, and return it
29 30 31 32 |
# File 'lib/extlib/simple_set.rb', line 29 def <<(value) self[value] = true self end |
#inspect ⇒ String
58 59 60 |
# File 'lib/extlib/simple_set.rb', line 58 def inspect "#<SimpleSet: {#{keys.map {|x| x.inspect}.join(", ")}}>" end |
#merge(arr) ⇒ SimpleSet
45 46 47 |
# File 'lib/extlib/simple_set.rb', line 45 def merge(arr) super(arr.inject({}) {|s,x| s[x] = true; s }) end |