Class: Racc::ISet
Overview
An “indexed” set. All items must respond to :ident.
Instance Attribute Summary collapse
-
#set ⇒ Object
readonly
Returns the value of attribute set.
Instance Method Summary collapse
- #[](key) ⇒ Object (also: #include?, #key?)
- #[]=(key, val) ⇒ Object
- #add(i) ⇒ Object
- #clear ⇒ Object
- #delete(key) ⇒ Object
- #dup ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(a = []) ⇒ ISet
constructor
A new instance of ISet.
- #size ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object (also: #inspect)
- #update(other) ⇒ Object
- #update_a(a) ⇒ Object
Constructor Details
#initialize(a = []) ⇒ ISet
Returns a new instance of ISet.
18 19 20 |
# File 'lib/racc/iset.rb', line 18 def initialize(a = []) @set = a end |
Instance Attribute Details
#set ⇒ Object (readonly)
Returns the value of attribute set.
22 23 24 |
# File 'lib/racc/iset.rb', line 22 def set @set end |
Instance Method Details
#[](key) ⇒ Object Also known as: include?, key?
28 29 30 |
# File 'lib/racc/iset.rb', line 28 def [](key) @set[key.ident] end |
#[]=(key, val) ⇒ Object
32 33 34 |
# File 'lib/racc/iset.rb', line 32 def []=(key, val) @set[key.ident] = val end |
#add(i) ⇒ Object
24 25 26 |
# File 'lib/racc/iset.rb', line 24 def add(i) @set[i.ident] = i end |
#clear ⇒ Object
82 83 84 |
# File 'lib/racc/iset.rb', line 82 def clear @set.clear end |
#delete(key) ⇒ Object
54 55 56 57 58 |
# File 'lib/racc/iset.rb', line 54 def delete(key) i = @set[key.ident] @set[key.ident] = nil i end |
#each(&block) ⇒ Object
60 61 62 |
# File 'lib/racc/iset.rb', line 60 def each(&block) @set.compact.each(&block) end |
#empty? ⇒ Boolean
78 79 80 |
# File 'lib/racc/iset.rb', line 78 def empty? @set.nitems == 0 end |
#size ⇒ Object
74 75 76 |
# File 'lib/racc/iset.rb', line 74 def size @set.nitems end |
#to_a ⇒ Object
64 65 66 |
# File 'lib/racc/iset.rb', line 64 def to_a @set.compact end |
#to_s ⇒ Object Also known as: inspect
68 69 70 |
# File 'lib/racc/iset.rb', line 68 def to_s "[#{@set.compact.join(' ')}]" end |
#update(other) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/racc/iset.rb', line 39 def update(other) s = @set o = other.set o.each_index do |idx| if t = o[idx] s[idx] = t end end end |
#update_a(a) ⇒ Object
49 50 51 52 |
# File 'lib/racc/iset.rb', line 49 def update_a(a) s = @set a.each {|i| s[i.ident] = i } end |