Class: Hamster::MutableSet

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/hamster/experimental/mutable_set.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Hamster::ReadCopyUpdate

Instance Method Details

#add(item) ⇒ Object



14
15
16
# File 'lib/hamster/experimental/mutable_set.rb', line 14

def add(item)
  transform { |set| set.add(item) }
end

#add?(item) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
# File 'lib/hamster/experimental/mutable_set.rb', line 19

def add?(item)
  added = false
  transform do |set|
    added = !set.include?(item)
    set.add(item)
  end
  added
end

#delete(item) ⇒ Object



28
29
30
# File 'lib/hamster/experimental/mutable_set.rb', line 28

def delete(item)
  transform { |set| set.delete(item) }
end

#delete?(item) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
# File 'lib/hamster/experimental/mutable_set.rb', line 32

def delete?(item)
  deleted = false
  transform do |set|
    deleted = set.include?(item)
    set.delete(item)
  end
  deleted
end