Class SymTbl
In: lib/sym_tbl.rb
Parent: Object

Methods

[]   []=   ancestors   desc   desc_one   each   has_key?   has_local_key?   include?   key?   key_convert   member?   merge   merge!   new   new_child   update  

Classes and Modules

Class SymTbl::Trigger

Attributes

father  [R] 
local  [R] 
sid  [R] 

Public Class methods

[Source]

# File lib/sym_tbl.rb, line 16
  def initialize ( father_env=nil, default=nil )
    @sid = (@@sid += 1)
    @local = Hash.new(default)
    if father_env.is_a? Hash
      @father = nil
      merge!(father_env)
    else
      @father = father_env
    end
  end

Public Instance methods

[Source]

# File lib/sym_tbl.rb, line 31
  def [] ( aKey )
    return nil if aKey == ''
    aKey = key_convert(aKey)
    result =
      if @local.has_key? aKey
        @local[aKey]
      elsif @father.nil?
        @local.default
      else
        @father[aKey]
      end
    result = result[] if result.is_a? Trigger
    result
  end

[Source]

# File lib/sym_tbl.rb, line 46
  def []= ( aKey, aValue )
    aKey = key_convert(aKey)
    @local[aKey] = aValue
  end

[Source]

# File lib/sym_tbl.rb, line 62
  def ancestors
    (@father.is_a?(SymTbl))? [self] + @father.ancestors : [self]
  end

[Source]

# File lib/sym_tbl.rb, line 75
  def desc
    ancestors.map{ |s| s.desc_one }.to_yaml
  end

[Source]

# File lib/sym_tbl.rb, line 66
  def desc_one
    if defined? @already_described
      return sid
    else
      @already_described = true
      return { sid => @local }
    end
  end

FIXME

[Source]

# File lib/sym_tbl.rb, line 52
  def each ( &block )
    key_set = Set.new
    blk = lambda do |k,v|
      block[k, v] unless key_set.include? k
      key_set << k
    end
    @local.each(&blk)
    @father.each(&blk) unless @father.nil?
  end

[Source]

# File lib/sym_tbl.rb, line 91
  def has_key?(key)
    key = key_convert(key)
    if @local.has_key?(key)
      true
    else
      if @father.nil?
        false
      else
        @father.has_key?(key)
      end
    end
  end

[Source]

# File lib/sym_tbl.rb, line 108
  def has_local_key?(key)
    @local.has_key?(key_convert(key))
  end
include?(key)

Alias for has_key?

key?(key)

Alias for has_key?

[Source]

# File lib/sym_tbl.rb, line 27
  def key_convert ( aKey )
    (aKey.is_a? Symbol)? aKey : aKey.to_s.to_sym
  end
member?(key)

Alias for has_key?

[Source]

# File lib/sym_tbl.rb, line 79
  def merge(other)
    symtbl = self.class.new(self)
    symtbl.merge!(other)
  end

[Source]

# File lib/sym_tbl.rb, line 84
  def merge!(other)
    other.each { |k, v| @local[key_convert(k)] = v }
    self
  end

[Source]

# File lib/sym_tbl.rb, line 112
  def new_child
    self.class.new(self)
  end
update(other)

Alias for merge!

[Validate]