Class: TypeProf::Core::Set

Inherits:
Object
  • Object
show all
Defined in:
lib/typeprof/core/util.rb

Constant Summary collapse

EMPTY =
empty.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Set

Returns a new instance of Set.



13
14
15
# File 'lib/typeprof/core/util.rb', line 13

def initialize(hash)
  @hash = hash
end

Class Method Details

.[](*elems) ⇒ Object



3
4
5
6
7
# File 'lib/typeprof/core/util.rb', line 3

def self.[](*elems)
  h = Hash.new(false)
  elems.each {|elem| h[elem] = true }
  new(h)
end

.emptyObject



9
10
11
# File 'lib/typeprof/core/util.rb', line 9

def self.empty
  new(Hash.new(false))
end

Instance Method Details

#-(other) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/typeprof/core/util.rb', line 62

def -(other)
  h = @hash.dup
  other.each do |elem|
    h.delete(elem)
  end
  Set.new(h)
end

#<<(elem) ⇒ Object



23
24
25
26
27
# File 'lib/typeprof/core/util.rb', line 23

def <<(elem)
  raise if @hash.include?(elem)
  @hash[elem] = true
  self
end

#clearObject



50
51
52
# File 'lib/typeprof/core/util.rb', line 50

def clear
  @hash.clear
end

#delete(elem) ⇒ Object



45
46
47
48
# File 'lib/typeprof/core/util.rb', line 45

def delete(elem)
  raise unless @hash.include?(elem)
  @hash.delete(elem)
end

#dupObject



19
20
21
# File 'lib/typeprof/core/util.rb', line 19

def dup
  Set.new(@hash.dup)
end

#each(&blk) ⇒ Object



37
38
39
# File 'lib/typeprof/core/util.rb', line 37

def each(&blk)
  @hash.each_key(&blk)
end

#empty?Boolean

Returns:



41
42
43
# File 'lib/typeprof/core/util.rb', line 41

def empty?
  @hash.empty?
end

#include?(elem) ⇒ Boolean

Returns:



29
30
31
# File 'lib/typeprof/core/util.rb', line 29

def include?(elem)
  @hash[elem]
end

#internal_hashObject



17
# File 'lib/typeprof/core/util.rb', line 17

def internal_hash = @hash

#merge(set) ⇒ Object

Raises:



33
34
35
# File 'lib/typeprof/core/util.rb', line 33

def merge(set)
  raise NotImplementedError
end

#pretty_print(q) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/typeprof/core/util.rb', line 70

def pretty_print(q)
  q.text "Set["
  q.group do
    q.nest(1) do
      @hash.each_key do |elem|
        q.breakable ""
        q.pp elem
        q.text ","
      end
    end
    q.breakable ""
  end
  q.text "]"
end

#sizeObject



58
59
60
# File 'lib/typeprof/core/util.rb', line 58

def size
  @hash.size
end

#to_aObject



54
55
56
# File 'lib/typeprof/core/util.rb', line 54

def to_a
  @hash.keys
end