Class: TypeProf::Core::Set
- Inherits:
-
Object
- Object
- TypeProf::Core::Set
- Defined in:
- lib/typeprof/core/util.rb
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.
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 |
#clear ⇒ Object
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 |
#each(&blk) ⇒ Object
33 34 35 |
# File 'lib/typeprof/core/util.rb', line 33 def each(&blk) @hash.each_key(&blk) end |
#empty? ⇒ Boolean
37 38 39 |
# File 'lib/typeprof/core/util.rb', line 37 def empty? @hash.empty? end |
#include?(elem) ⇒ Boolean
25 26 27 |
# File 'lib/typeprof/core/util.rb', line 25 def include?(elem) @hash[elem] end |
#internal_hash ⇒ Object
13 |
# File 'lib/typeprof/core/util.rb', line 13 def internal_hash = @hash |
#merge(set) ⇒ Object
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 |
#size ⇒ Object
54 55 56 |
# File 'lib/typeprof/core/util.rb', line 54 def size @hash.size end |
#to_a ⇒ Object
50 51 52 |
# File 'lib/typeprof/core/util.rb', line 50 def to_a @hash.keys end |