Class: Tribe::SafeSet
- Inherits:
-
Object
- Object
- Tribe::SafeSet
- Defined in:
- lib/tribe/safe_set.rb
Instance Method Summary collapse
- #add(item) ⇒ Object
- #clear ⇒ Object
- #delete(item) ⇒ Object
- #delete?(item) ⇒ Boolean
- #each(&block) ⇒ Object
-
#initialize ⇒ SafeSet
constructor
A new instance of SafeSet.
- #size ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize ⇒ SafeSet
Returns a new instance of SafeSet.
7 8 9 10 11 12 |
# File 'lib/tribe/safe_set.rb', line 7 def initialize @mutex = Mutex.new @set = Set.new return nil end |
Instance Method Details
#add(item) ⇒ Object
14 15 16 17 18 |
# File 'lib/tribe/safe_set.rb', line 14 def add(item) @mutex.synchronize do return @set.add(item) end end |
#clear ⇒ Object
40 41 42 43 44 |
# File 'lib/tribe/safe_set.rb', line 40 def clear @mutex.synchronize do return @set.clear end end |
#delete(item) ⇒ Object
20 21 22 23 24 |
# File 'lib/tribe/safe_set.rb', line 20 def delete(item) @mutex.synchronize do return @set.delete(item) end end |
#delete?(item) ⇒ Boolean
26 27 28 29 30 |
# File 'lib/tribe/safe_set.rb', line 26 def delete?(item) @mutex.synchronize do return @set.delete?(item) end end |
#each(&block) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/tribe/safe_set.rb', line 32 def each(&block) @mutex.synchronize do return @set.each do |item| yield(item) end end end |
#size ⇒ Object
46 47 48 49 50 |
# File 'lib/tribe/safe_set.rb', line 46 def size @mutex.synchronize do return @set.size end end |
#to_a ⇒ Object
52 53 54 55 56 |
# File 'lib/tribe/safe_set.rb', line 52 def to_a @mutex.synchronize do return @set.to_a end end |