Class: Merb::SimpleSet
Instance Method Summary collapse
-
#<<(value) ⇒ Object
Parameters value<Object>:: Value to add to set.
-
#initialize(arr = []) ⇒ SimpleSet
constructor
Parameters arr<Array>:: Initial set values.
-
#inspect ⇒ Object
Returns String:: A human readable version of the set.
-
#merge(arr) ⇒ Object
Parameters arr<Array>:: Values to merge with set.
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 = []) ⇒ SimpleSet
Parameters
- arr<Array>
-
Initial set values.
Returns
- Array
-
The array the Set was initialized with
9 10 11 |
# File 'lib/merb-core/core_ext/set.rb', line 9 def initialize(arr = []) arr.each {|x| self[x] = true} end |
Instance Method Details
#<<(value) ⇒ Object
Parameters
- value<Object>
-
Value to add to set.
Returns
true
18 19 20 |
# File 'lib/merb-core/core_ext/set.rb', line 18 def <<(value) self[value] = true end |
#inspect ⇒ Object
Returns
- String
-
A human readable version of the set.
33 34 35 |
# File 'lib/merb-core/core_ext/set.rb', line 33 def inspect "#<SimpleSet: {#{keys.map {|x| x.inspect}.join(", ")}}>" end |
#merge(arr) ⇒ Object
Parameters
- arr<Array>
-
Values to merge with set.
Returns
- SimpleSet
-
The set after the Array was merged in.
27 28 29 |
# File 'lib/merb-core/core_ext/set.rb', line 27 def merge(arr) super(arr.inject({}) {|s,x| s[x] = true; s }) end |