Class: RSpec::Core::Set

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rspec/core/set.rb

Overview

We use this to replace `::Set` so we can have the advantage of constant time key lookups for unique arrays but without the potential to pollute a developers environment with an extra piece of the stdlib. This helps to prevent false positive builds.

Instance Method Summary collapse

Constructor Details

#initialize(array = []) ⇒ Set



14
15
16
17
# File 'lib/rspec/core/set.rb', line 14

def initialize(array=[])
  @values = {}
  merge(array)
end

Instance Method Details

#<<(key) ⇒ Object



23
24
25
26
# File 'lib/rspec/core/set.rb', line 23

def <<(key)
  @values[key] = true
  self
end

#clearObject



48
49
50
51
# File 'lib/rspec/core/set.rb', line 48

def clear
  @values.clear
  self
end

#delete(key) ⇒ Object



28
29
30
# File 'lib/rspec/core/set.rb', line 28

def delete(key)
  @values.delete(key)
end

#each(&block) ⇒ Object



32
33
34
35
# File 'lib/rspec/core/set.rb', line 32

def each(&block)
  @values.keys.each(&block)
  self
end

#empty?Boolean



19
20
21
# File 'lib/rspec/core/set.rb', line 19

def empty?
  @values.empty?
end

#include?(key) ⇒ Boolean



37
38
39
# File 'lib/rspec/core/set.rb', line 37

def include?(key)
  @values.key?(key)
end

#merge(values) ⇒ Object



41
42
43
44
45
46
# File 'lib/rspec/core/set.rb', line 41

def merge(values)
  values.each do |key|
    @values[key] = true
  end
  self
end