Class TkVarAccess
In: tk/lib/tk/variable.rb
Parent: TkVariable

Methods

new   new   new_hash  

Public Class methods

[Source]

# File tk/lib/tk/variable.rb, line 946
  def self.new(name, *args)
    return TkVar_ID_TBL[name] if TkVar_ID_TBL[name]
    super(name, *args)
  end

[Source]

# File tk/lib/tk/variable.rb, line 961
  def initialize(varname, val=nil)
    @id = varname
    TkVar_ID_TBL[@id] = self

    @def_default = false
    @default_val = nil

    @trace_var  = nil
    @trace_elem = nil
    @trace_opts = nil

    # teach Tk-ip that @id is global var

    INTERP._invoke_without_enc('global', @id)

    if val
      if val.kind_of?(Hash)
        # assoc-array variable

        self[''] = 0
        self.clear
      end
      #s = '"' + _get_eval_string(val).gsub(/[\[\]$"]/, '\\\\\&') + '"' #"

      #s = '"' + _get_eval_string(val).gsub(/[\[\]$"\\]/, '\\\\\&') + '"' #"

      #INTERP._eval(Kernel.format('global %s; set %s %s', @id, @id, s))

      #INTERP._set_global_var(@id, _toUTF8(_get_eval_string(val)))

      self.value = val
    end
  end

[Source]

# File tk/lib/tk/variable.rb, line 951
  def self.new_hash(name, *args)
    return TkVar_ID_TBL[name] if TkVar_ID_TBL[name]
    INTERP._invoke_without_enc('global', name)
    if args.empty? && INTERP._invoke_without_enc('array', 'exist', name) == '0'
      self.new(name, {})  # force creating

    else
      self.new(name, *args)
    end
  end

[Validate]