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

### Methods

new new new_hash

### Public Class methods

new(name, *args)

[Source]

    # File tk/lib/tk/variable.rb, line 1532
      def self.new(name, *args)
        if name.kind_of?(TkVariable)
          name.value = args[0] unless args.empty?
          return name
        end

        if v = TkVar_ID_TBL[name]
          v.value = args[0] unless args.empty?
          return v
        end

        super(name, *args)
      end

new(varname, val=nil)

[Source]

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

        @var  = @id
        @elem = nil

        @def_default = false
        @default_val = nil

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

        @type = nil
        var = self
        @element_type = Hash.new{|k,v| var.default_value_type }

        # is an element?
        if @id =~ /^([^(]+)\((.+)\)$/
          # is an element --> var == $1, elem == $2
          @var  = $1
          @elem = $2
        end

        # teach Tk-ip that @id is global var
        INTERP._invoke_without_enc('global', @var)
    ??

        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

new_hash(name, *args)

[Source]

    # File tk/lib/tk/variable.rb, line 1546
      def self.new_hash(name, *args)
        if name.kind_of?(TkVariable)
          unless name.is_hash?
            fail ArgumentError, "already exist as a scalar variable"
          end
          name.value = args[0] unless args.empty?
          return name
        end

        if v = TkVar_ID_TBL[name]
          unless v.is_hash?
            fail ArgumentError, "already exist as a scalar variable"
          end
          v.value = args[0] unless args.empty?
          return v
        end

        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]