123456789_123456789_123456789_123456789_123456789_

Class: Racc::ISet

Relationships & Source Files
Inherits: Object
Defined in: lib/racc/iset.rb

Overview

An “indexed” set. All items must respond to :ident.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(a = []) ⇒ ISet

[ GitHub ]

  
# File 'lib/racc/iset.rb', line 17

def initialize(a = [])
  @set = a
end

Instance Attribute Details

#empty?Boolean (readonly)

[ GitHub ]

  
# File 'lib/racc/iset.rb', line 77

def empty?
  @set.nitems == 0
end

#set (readonly)

[ GitHub ]

  
# File 'lib/racc/iset.rb', line 21

attr_reader :set

Instance Method Details

#[](key) Also known as: #include?, #key?

[ GitHub ]

  
# File 'lib/racc/iset.rb', line 27

def [](key)
  @set[key.ident]
end

#[]=(key, val)

[ GitHub ]

  
# File 'lib/racc/iset.rb', line 31

def []=(key, val)
  @set[key.ident] = val
end

#add(i)

[ GitHub ]

  
# File 'lib/racc/iset.rb', line 23

def add(i)
  @set[i.ident] = i
end

#clear

[ GitHub ]

  
# File 'lib/racc/iset.rb', line 81

def clear
  @set.clear
end

#delete(key)

[ GitHub ]

  
# File 'lib/racc/iset.rb', line 53

def delete(key)
  i = @set[key.ident]
  @set[key.ident] = nil
  i
end

#dup

[ GitHub ]

  
# File 'lib/racc/iset.rb', line 85

def dup
  ISet.new(@set.dup)
end

#each(&block)

[ GitHub ]

  
# File 'lib/racc/iset.rb', line 59

def each(&block)
  @set.compact.each(&block)
end

#include?(key)

Alias for #[].

[ GitHub ]

  
# File 'lib/racc/iset.rb', line 35

alias include? []

#inspect

Alias for #to_s.

[ GitHub ]

  
# File 'lib/racc/iset.rb', line 71

alias inspect to_s

#key?(key)

Alias for #[].

[ GitHub ]

  
# File 'lib/racc/iset.rb', line 36

alias key? []

#size

[ GitHub ]

  
# File 'lib/racc/iset.rb', line 73

def size
  @set.nitems
end

#to_a

[ GitHub ]

  
# File 'lib/racc/iset.rb', line 63

def to_a
  @set.compact
end

#to_s Also known as: #inspect

[ GitHub ]

  
# File 'lib/racc/iset.rb', line 67

def to_s
  "[#{@set.compact.join(' ')}]"
end

#update(other)

[ GitHub ]

  
# 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)

[ GitHub ]

  
# File 'lib/racc/iset.rb', line 48

def update_a(a)
  s = @set
  a.each {|i| s[i.ident] = i }
end