Class: TypeProf::Core::Set
- Inherits:
-
Object
- Object
- TypeProf::Core::Set
- Defined in:
- lib/typeprof/core/util.rb
Constant Summary collapse
- EMPTY =
empty.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #-(other) ⇒ Object
- #<<(elem) ⇒ Object
- #clear ⇒ Object
- #delete(elem) ⇒ Object
- #dup ⇒ Object
- #each(&blk) ⇒ Object
- #empty? ⇒ Boolean
- #include?(elem) ⇒ Boolean
-
#initialize(hash) ⇒ Set
constructor
A new instance of Set.
- #internal_hash ⇒ Object
- #merge(set) ⇒ Object
- #pretty_print(q) ⇒ Object
- #size ⇒ Object
- #to_a ⇒ Object
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 |
.empty ⇒ Object
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 |
#clear ⇒ Object
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 |
#each(&blk) ⇒ Object
37 38 39 |
# File 'lib/typeprof/core/util.rb', line 37 def each(&blk) @hash.each_key(&blk) end |
#empty? ⇒ Boolean
41 42 43 |
# File 'lib/typeprof/core/util.rb', line 41 def empty? @hash.empty? end |
#include?(elem) ⇒ Boolean
29 30 31 |
# File 'lib/typeprof/core/util.rb', line 29 def include?(elem) @hash[elem] end |
#internal_hash ⇒ Object
17 |
# File 'lib/typeprof/core/util.rb', line 17 def internal_hash = @hash |
#merge(set) ⇒ Object
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 |
#size ⇒ Object
58 59 60 |
# File 'lib/typeprof/core/util.rb', line 58 def size @hash.size end |
#to_a ⇒ Object
54 55 56 |
# File 'lib/typeprof/core/util.rb', line 54 def to_a @hash.keys end |