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.
19 20 21 |
# File 'lib/racc/iset.rb', line 19 def initialize(a = []) @set = a end |
Instance Attribute Details
#set ⇒ Object (readonly)
Returns the value of attribute set.
23 24 25 |
# File 'lib/racc/iset.rb', line 23 def set @set end |
Instance Method Details
#[](key) ⇒ Object Also known as: include?, key?
29 30 31 |
# File 'lib/racc/iset.rb', line 29 def [](key) @set[key.ident] end |
#[]=(key, val) ⇒ Object
33 34 35 |
# File 'lib/racc/iset.rb', line 33 def []=(key, val) @set[key.ident] = val end |
#add(i) ⇒ Object
25 26 27 |
# File 'lib/racc/iset.rb', line 25 def add(i) @set[i.ident] = i end |
#clear ⇒ Object
83 84 85 |
# File 'lib/racc/iset.rb', line 83 def clear @set.clear end |
#delete(key) ⇒ Object
55 56 57 58 59 |
# File 'lib/racc/iset.rb', line 55 def delete(key) i = @set[key.ident] @set[key.ident] = nil i end |
#each(&block) ⇒ Object
61 62 63 |
# File 'lib/racc/iset.rb', line 61 def each(&block) @set.compact.each(&block) end |
#empty? ⇒ Boolean
79 80 81 |
# File 'lib/racc/iset.rb', line 79 def empty? @set.nitems == 0 end |
#size ⇒ Object
75 76 77 |
# File 'lib/racc/iset.rb', line 75 def size @set.nitems end |
#to_a ⇒ Object
65 66 67 |
# File 'lib/racc/iset.rb', line 65 def to_a @set.compact end |
#to_s ⇒ Object Also known as: inspect
69 70 71 |
# File 'lib/racc/iset.rb', line 69 def to_s "[#{@set.compact.join(' ')}]" end |
#update(other) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/racc/iset.rb', line 40 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
50 51 52 53 |
# File 'lib/racc/iset.rb', line 50 def update_a(a) s = @set a.each {|i| s[i.ident] = i } end |