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.
17 18 19 |
# File 'lib/racc/iset.rb', line 17 def initialize(a = []) @set = a end |
Instance Attribute Details
#set ⇒ Object (readonly)
Returns the value of attribute set.
21 22 23 |
# File 'lib/racc/iset.rb', line 21 def set @set end |
Instance Method Details
#[](key) ⇒ Object Also known as: include?, key?
27 28 29 |
# File 'lib/racc/iset.rb', line 27 def [](key) @set[key.ident] end |
#[]=(key, val) ⇒ Object
31 32 33 |
# File 'lib/racc/iset.rb', line 31 def []=(key, val) @set[key.ident] = val end |
#add(i) ⇒ Object
23 24 25 |
# File 'lib/racc/iset.rb', line 23 def add(i) @set[i.ident] = i end |
#clear ⇒ Object
81 82 83 |
# File 'lib/racc/iset.rb', line 81 def clear @set.clear end |
#delete(key) ⇒ Object
53 54 55 56 57 |
# File 'lib/racc/iset.rb', line 53 def delete(key) i = @set[key.ident] @set[key.ident] = nil i end |
#each(&block) ⇒ Object
59 60 61 |
# File 'lib/racc/iset.rb', line 59 def each(&block) @set.compact.each(&block) end |
#empty? ⇒ Boolean
77 78 79 |
# File 'lib/racc/iset.rb', line 77 def empty? @set.nitems == 0 end |
#size ⇒ Object
73 74 75 |
# File 'lib/racc/iset.rb', line 73 def size @set.nitems end |
#to_a ⇒ Object
63 64 65 |
# File 'lib/racc/iset.rb', line 63 def to_a @set.compact end |
#to_s ⇒ Object Also known as: inspect
67 68 69 |
# File 'lib/racc/iset.rb', line 67 def to_s "[#{@set.compact.join(' ')}]" end |
#update(other) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/racc/iset.rb', line 38 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
48 49 50 51 |
# File 'lib/racc/iset.rb', line 48 def update_a(a) s = @set a.each {|i| s[i.ident] = i } end |