Class: TypeProf::Core::Set

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Set

Returns a new instance of Set.



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

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

Instance Method Details

#-(other) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/typeprof/core/util.rb', line 58

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

#<<(elem) ⇒ Object



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

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

#clearObject



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

def clear
  @hash.clear
end

#delete(elem) ⇒ Object



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

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

#dupObject



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

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

#each(&blk) ⇒ Object



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

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

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  @hash.empty?
end

#include?(elem) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#internal_hashObject



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

def internal_hash = @hash

#merge(set) ⇒ Object

Raises:

  • (NotImplementedError)


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

def merge(set)
  raise NotImplementedError
end

#pretty_print(q) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/typeprof/core/util.rb', line 66

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



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

def size
  @hash.size
end

#to_aObject



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

def to_a
  @hash.keys
end