Class: TkVariable

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

### Methods

% & * ** + - / <=> == =~ [] []= []= _trace_vinfo_for_element bool bool= bool_element bool_type= callback clear coerce default_element_value_type default_proc default_value default_value= default_value_type default_value_type= element_lappend element_lget element_lget_f element_lget_i element_lindex element_lset element_to_a element_to_f element_to_i element_to_s element_to_sym eventloop_tkwait eventloop_wait exist? id inspect is_hash? is_scalar? keys lappend lget lget_f lget_i lindex list list= list_element list_type= lset new new_hash nonzero? numeric numeric= numeric_element numeric_type= numlist numlist= numlist_element numlist_type= procedure procedure= procedure_element procedure_type= ref remove remove set_bool set_bool_element set_bool_element_type set_bool_type set_default_element_value_type set_default_value set_default_value_type set_element_value set_element_value_type set_list set_list_element set_list_element_type set_list_type set_numeric set_numeric_element set_numeric_element_type set_numeric_type set_numlist set_numlist_element set_numlist_element_type set_numlist_type set_procedure set_procedure_element set_procedure_element_type set_procedure_type set_string set_string_element set_string_element_type set_string_type set_symbol set_symbol_element set_symbol_element_type set_symbol_type set_value set_value_type set_variable set_variable_element set_variable_element_type set_variable_type set_window set_window_element set_window_element_type set_window_type size string string= string_element string_type= symbol symbol= symbol_element symbol_type= thread_tkwait thread_wait tkwait to_a to_eval to_f to_i to_s to_sym trace trace_callback trace_element trace_vdelete trace_vdelete_for_element trace_vinfo undef_default unset unset update value value= value= value_type= variable variable= variable_element variable_type= wait window window= window_element window_type= zero? |

### Included Modules

Tk Comparable

### Constants

TkCommandNames | = | ['vwait'.freeze].freeze |  | TkCommandNames = [‘tkwait’.freeze].freeze
TkVar_CB_TBL | = | TkCore::INTERP.create_table |  | TkVar_CB_TBL = {} TkVar_ID_TBL = {}
TkVar_ID_TBL | = | TkCore::INTERP.create_table
Tk_VARIABLE_ID | = | ["v".freeze, "00000".taint].freeze
USE_TCLs_SET_VARIABLE_FUNCTIONS | = | true

### Public Class methods

callback(id, name1, name2, op)

def TkVariable.callback(args)

[Source]

    # File tk/lib/tk/variable.rb, line 45
      def TkVariable.callback(id, name1, name2, op)
        #name1,name2,op = tk_split_list(args)
        #name1,name2,op = tk_split_simplelist(args)
        if TkVar_CB_TBL[id]
          #_get_eval_string(TkVar_CB_TBL[name1].trace_callback(name2,op))
          begin
            _get_eval_string(TkVar_CB_TBL[id].trace_callback(name2, op))
          rescue SystemExit
            exit(0)
          rescue Interrupt
            exit!(1)
          rescue Exception => e
            begin
              msg = _toUTF8(e.class.inspect) + ': ' +
                    _toUTF8(e.message) + "\n" +
                    "\n---< backtrace of Ruby side >-----\n" +
                    _toUTF8(e.backtrace.join("\n")) +
                    "\n---< backtrace of Tk side >-------"
              msg.instance_variable_set(:@encoding, 'utf-8')
            rescue Exception
              msg = e.class.inspect + ': ' + e.message + "\n" +
                    "\n---< backtrace of Ruby side >-----\n" +
                    e.backtrace.join("\n") +
                    "\n---< backtrace of Tk side >-------"
            end
            fail(e, msg)
          end
    ??
        else
          ''
        end
      end

new(val="", type=nil)

[Source]

    # File tk/lib/tk/variable.rb, line 268
      def initialize(val="", type=nil)
        # @id = Tk_VARIABLE_ID.join('')
        @id = Tk_VARIABLE_ID.join(TkCore::INTERP._ip_id_)
        Tk_VARIABLE_ID[1].succ!
        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 }

        self.default_value_type = type

        begin
          INTERP._unset_global_var(@id)
        rescue
        end

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

        # create and init
        if val.kind_of?(Hash)
          # assoc-array variable
          self[''] = 0
          self.clear
        end
        self.value = val

    ??
    ??
      end

new_hash(val = {})

[Source]

    # File tk/lib/tk/variable.rb, line 92
      def self.new_hash(val = {})
        if val.kind_of?(Hash)
          self.new(val)
        else
          fail ArgumentError, 'Hash is expected'
        end
      end

### Public Instance methods

%(other)

[Source]

    # File tk/lib/tk/variable.rb, line 1187
      def %(other)
        num_or_str(self._value) % other.to_i
        #begin
        #  number(self._value) % other
        #rescue
        #  self._value % other
        #end
      end

&(other)

[Source]

    # File tk/lib/tk/variable.rb, line 1141
      def &(other)
        if other.kind_of?(Array)
          self.to_a & other.to_a
        else
          self.to_i & other.to_i
        end
      end

*(other)

[Source]

    # File tk/lib/tk/variable.rb, line 1176
      def *(other)
        num_or_str(self._value) * other.to_i
        #begin
        #  number(self._value) * other
        #rescue
        #  self._value * other
        #end
      end

**(other)

[Source]

    # File tk/lib/tk/variable.rb, line 1195
      def **(other)
        number(self._value) ** other
      end

+(other)

[Source]

    # File tk/lib/tk/variable.rb, line 1155
      def +(other)
        case other
        when Array
          self.to_a + other
        when String
          self._value + other
        else
          begin
            number(self._value) + other
          rescue
            self._value + other.to_s
          end
        end
      end

-(other)

[Source]

    # File tk/lib/tk/variable.rb, line 1169
      def -(other)
        if other.kind_of?(Array)
          self.to_a - other
        else
          number(self._value) - other
        end
      end

/(other)

[Source]

    # File tk/lib/tk/variable.rb, line 1184
      def /(other)
        number(self._value) / other
      end

<=>(other)

[Source]

    # File tk/lib/tk/variable.rb, line 1233
      def <=>(other)
        if other.kind_of?(TkVariable)
          begin
            val = other.numeric
            other = val
          rescue
            other = other._value
          end
        elsif other.kind_of?(Numeric)
          begin
            return self.numeric <=> other
          rescue
            return self._value <=> other.to_s
          end
        elsif other.kind_of?(Array)
          return self.list <=> other
        else
          return self._value <=> other
        end
      end

==(other)

[Source]

    # File tk/lib/tk/variable.rb, line 1202
      def ==(other)
        case other
        when TkVariable
          #self.equal?(other)
          self._value == other._value
        when String
          self.to_s == other
        when Symbol
          self.to_sym == other
        when Integer
          self.to_i == other
        when Float
          self.to_f == other
        when Array
          self.to_a == other
        when Hash
          # false if self is not an assoc array
          self._value == other
        else
          # false
          self._value == _get_eval_string(other)
        end
      end

=~(other)

[Source]

    # File tk/lib/tk/variable.rb, line 1198
      def =~(other)
        self._value =~ other
      end

[](*idxs)

[Source]

    # File tk/lib/tk/variable.rb, line 672
      def [](*idxs)
        _to_default_element_type(idxs, _element_value(*idxs))
      end

[]=(*args)

[Source]

    # File tk/lib/tk/variable.rb, line 516
      def []=(*args)
        val = args.pop
        type = default_element_value_type(args)
        val = val._value if !type && type != :variable && val.kind_of?(TkVariable)
        index = args.collect{|idx| _get_eval_string(idx, true)}.join(',')
        _fromUTF8(INTERP._set_global_var2(@id, index, _get_eval_string(val, true)))
        #_fromUTF8(INTERP._set_global_var2(@id, _toUTF8(_get_eval_string(index)),
        #                                 _toUTF8(_get_eval_string(val))))
        #_fromUTF8(INTERP._set_global_var2(@id, _get_eval_string(index, true),
        #                                 _get_eval_string(val, true)))
      end

[]=(*args)

[Source]

    # File tk/lib/tk/variable.rb, line 633
      def []=(*args)
        val = args.pop
        type = default_element_value_type(args)
        val = val._value if !type && type != :variable && val.kind_of?(TkVariable)
        index = args.collect{|idx| _get_eval_string(idx)}.join(',')
        INTERP._eval(Kernel.format('global %s; set %s(%s) %s', @id, @id,
                                  index, _get_eval_string(val)))
        #INTERP._eval(Kernel.format('global %s; set %s(%s) %s', @id, @id,
        #                          _get_eval_string(index), _get_eval_string(val)))
        #INTERP._eval(Kernel.format('set %s(%s) %s', @id,
        #                          _get_eval_string(index), _get_eval_string(val)))
        #INTERP._eval('set ' + @id + '(' + _get_eval_string(index) + ') ' +
        #            _get_eval_string(val))
      end

_trace_vinfo_for_element(elem)

[Source]

    # File tk/lib/tk/variable.rb, line 1385
      def _trace_vinfo_for_element(elem)
        if @elem
          fail(RuntimeError,
               "invalid for a TkVariable which denotes an element of Tcl's array")
        end
        return [] unless @trace_elem
        return [] unless @trace_elem[elem]
        @trace_elem[elem].dup
      end

bool()

[Source]

    # File tk/lib/tk/variable.rb, line 753
      def bool
        TkComm.bool(_value)
    ??
      end

bool=(val)

Alias for set_bool

bool_element(*idxs)

[Source]

    # File tk/lib/tk/variable.rb, line 765
      def bool_element(*idxs)
        TkComm.bool(_element_value(*idxs))
      end

bool_type=(val)

Alias for set_bool_type

clear()

[Source]

    # File tk/lib/tk/variable.rb, line 429
      def clear
        if (is_scalar?)
          fail RuntimeError, 'cannot clear a scalar variable'
        end
        keys.each{|k| unset(k)}
        self
      end

coerce(other)

[Source]

    # File tk/lib/tk/variable.rb, line 1122
      def coerce(other)
        case other
        when TkVariable
          [other._value, self._value]
        when String
          [other, self.to_s]
        when Symbol
          [other, self.to_sym]
        when Integer
          [other, self.to_i]
        when Float
          [other, self.to_f]
        when Array
          [other, self.to_a]
        else
          [other, self._value]
        end
      end

default_element_value_type(idxs)

[Source]

    # File tk/lib/tk/variable.rb, line 134
      def default_element_value_type(idxs)
        if idxs.kind_of?(Array)
          index = idxs.collect{|idx| _get_eval_string(idx, true)}.join(',')
        else
          index = _get_eval_string(idxs, true)
        end
        @element_type[index]
      end

default_proc(cmd = Proc.new)

[Source]

    # File tk/lib/tk/variable.rb, line 119
      def default_proc(cmd = Proc.new)
        @def_default = :proc
        @default_val = cmd
        self
      end

default_value(val=nil, &b)

default_value is available only when the variable is an assoc array.

[Source]

    # File tk/lib/tk/variable.rb, line 103
      def default_value(val=nil, &b)
        if b
          @def_default = :proc
          @default_val = proc(&b)
        else
          @def_default = :val
          @default_val = val
        end
        self
      end

default_value=(val)

Alias for set_default_value

default_value_type()

[Source]

    # File tk/lib/tk/variable.rb, line 131
      def default_value_type
        @type
      end

default_value_type=(type)

Alias for set_default_value_type

element_lappend(idxs, *elems)

[Source]

    # File tk/lib/tk/variable.rb, line 1069
      def element_lappend(idxs, *elems)
        if idxs.kind_of?(Array)
          idxs = idxs.collect{|idx| _get_eval_string(idx, true)}.join(',')
        end
        tk_call('lappend', "#{@id}(#{idxs})", *elems)
        self
      end

element_lget(elem_idxs, idx)

Alias for element_lindex

element_lget_f(elem_idxs, idx)

[Source]

    # File tk/lib/tk/variable.rb, line 1101
      def element_lget_f(elem_idxs, idx)
        number(element_lget(elem_idxs, idx)).to_f
      end

element_lget_i(elem_idxs, idx)

[Source]

    # File tk/lib/tk/variable.rb, line 1094
      def element_lget_i(elem_idxs, idx)
        number(element_lget(elem_idxs, idx)).to_i
      end

element_lindex(elem_idxs, idx)

[Source]

    # File tk/lib/tk/variable.rb, line 1081
      def element_lindex(elem_idxs, idx)
        if elem_idxs.kind_of?(Array)
          val = _element_value(*elem_idxs)
        else
          val = _element_value(elem_idxs)
        end
        tk_call('lindex', val, idx)
      end

element_lset(elem_idxs, idx, val)

[Source]

    # File tk/lib/tk/variable.rb, line 1109
      def element_lset(elem_idxs, idx, val)
        if elem_idxs.kind_of?(Array)
          idxs = elem_idxs.collect{|i| _get_eval_string(i, true)}.join(',')
        end
        tk_call('lset', "#{@id}(#{idxs})", idx, val)
        self
      end

element_to_a(*idxs)

Alias for list_element

element_to_f(*idxs)

[Source]

    # File tk/lib/tk/variable.rb, line 918
      def element_to_f(*idxs)
        number(_element_value(*idxs)).to_f
      end

element_to_i(*idxs)

[Source]

    # File tk/lib/tk/variable.rb, line 911
      def element_to_i(*idxs)
        number(_element_value(*idxs)).to_i
      end

element_to_s(*idxs)

[Source]

    # File tk/lib/tk/variable.rb, line 927
      def element_to_s(*idxs)
        _element_value(*idxs)
      end

element_to_sym(*idxs)

[Source]

    # File tk/lib/tk/variable.rb, line 963
      def element_to_sym(*idxs)
        _element_value(*idxs).intern
      end

eventloop_tkwait()

[Source]

    # File tk/lib/tk/variable.rb, line 374
      def eventloop_tkwait
        wait(false, true)
      end

eventloop_wait(check_root = false)

[Source]

    # File tk/lib/tk/variable.rb, line 365
      def eventloop_wait(check_root = false)
        wait(false, check_root)
      end

exist?(*elems)

[Source]

    # File tk/lib/tk/variable.rb, line 401
      def exist?(*elems)
        INTERP._invoke_without_enc('global', @id)
        if elems.empty?
          TkComm.bool(tk_call('info', 'exist', @id))
        else
          # array
          index = elems.collect{|idx| _get_eval_string(idx, true)}.join(',')
          TkComm.bool(tk_call('info', 'exist', "#{@id}")) &&
            TkComm.bool(tk_call('info', 'exist', "#{@id}(#{index})"))
        end
      end

id()

[Source]

    # File tk/lib/tk/variable.rb, line 381
      def id
        @id
      end

inspect()

[Source]

    # File tk/lib/tk/variable.rb, line 1117
      def inspect
        #Kernel.format "#<TkVariable: %s>", @id
        '#<TkVariable: ' + @id + '>'
      end

is_hash?()

[Source]

    # File tk/lib/tk/variable.rb, line 390
      def is_hash?
        #ITNERP._eval("global #{@id}; array exist #{@id}") == '1'
        INTERP._invoke_without_enc('global', @id)
        # INTERP._invoke_without_enc('array', 'exist', @id) == '1'
        TkComm.bool(INTERP._invoke_without_enc('array', 'exist', @id))
      end

is_scalar?()

[Source]

    # File tk/lib/tk/variable.rb, line 397
      def is_scalar?
        ! is_hash?
      end

keys()

[Source]

    # File tk/lib/tk/variable.rb, line 413
      def keys
        if (is_scalar?)
          fail RuntimeError, 'cannot get keys from a scalar variable'
        end
        #tk_split_simplelist(INTERP._eval("global #{@id}; array get #{@id}"))
        INTERP._invoke_without_enc('global', @id)
        #tk_split_simplelist(INTERP._fromUTF8(INTERP._invoke_without_enc('array', 'names', @id)))
        tk_split_simplelist(INTERP._invoke_without_enc('array', 'names', @id),
                            false, true)
      end

lappend(*elems)

[Source]

    # File tk/lib/tk/variable.rb, line 1065
      def lappend(*elems)
        tk_call('lappend', @id, *elems)
        self
      end

lget(idx)

Alias for lindex

lget_f(idx)

[Source]

    # File tk/lib/tk/variable.rb, line 1098
      def lget_f(idx)
        number(lget(idx)).to_f
      end

lget_i(idx)

[Source]

    # File tk/lib/tk/variable.rb, line 1091
      def lget_i(idx)
        number(lget(idx)).to_i
      end

lindex(idx)

[Source]

    # File tk/lib/tk/variable.rb, line 1077
      def lindex(idx)
        tk_call('lindex', self._value, idx)
      end

list()

[Source]

    # File tk/lib/tk/variable.rb, line 993
      def list
        #tk_split_list(value)
        tk_split_simplelist(_value)
      end

list=(val)

Alias for set_list

list_element(*idxs)

[Source]

    # File tk/lib/tk/variable.rb, line 998
      def list_element(*idxs)
        tk_split_simplelist(_element_value(*idxs))
      end

list_type=(val)

Alias for set_list_type

lset(idx, val)

[Source]

    # File tk/lib/tk/variable.rb, line 1105
      def lset(idx, val)
        tk_call('lset', @id, idx, val)
        self
      end

nonzero?()

[Source]

    # File tk/lib/tk/variable.rb, line 1229
      def nonzero?
        !(numeric.zero?)
      end

numeric()

[Source]

    # File tk/lib/tk/variable.rb, line 708
      def numeric
        number(_value)
      end

numeric=(val)

Alias for set_numeric

numeric_element(*idxs)

[Source]

    # File tk/lib/tk/variable.rb, line 711
      def numeric_element(*idxs)
        number(_element_value(*idxs))
      end

numeric_type=(val)

Alias for set_numeric_type

numlist()

[Source]

    # File tk/lib/tk/variable.rb, line 1003
      def numlist
        list.collect!{|val| number(val)}
      end

numlist=(val)

Alias for set_numlist

numlist_element(*idxs)

[Source]

    # File tk/lib/tk/variable.rb, line 1006
      def numlist_element(*idxs)
        list_element(*idxs).collect!{|val| number(val)}
      end

numlist_type=(val)

Alias for set_numlist_type

procedure()

[Source]

    # File tk/lib/tk/variable.rb, line 877
      def procedure
        TkComm.procedure(self._value)
      end

procedure=(cmd)

Alias for set_procedure

procedure_element(*idxs)

[Source]

    # File tk/lib/tk/variable.rb, line 880
      def procedure_element(*idxs)
        TkComm.procedure(_element_value(*idxs))
      end

procedure_type=(cmd)

Alias for set_procedure_type

ref(*idxs)

[Source]

    # File tk/lib/tk/variable.rb, line 385
      def ref(*idxs)
        # "#{@id}(#{idxs.collect{|idx| _get_eval_string(idx)}.join(',')})"
        TkVarAccess.new("#{@id}(#{idxs.collect{|idx| _get_eval_string(idx)}.join(',')})")
      end

remove(*elems)

Alias for unset

remove(*elems)

Alias for unset

set_bool(val)

[Source]

    # File tk/lib/tk/variable.rb, line 768
      def set_bool(val)
        if ! val
          self.value = '0'
        else
          case val.to_s.downcase
          when 'false', '0', 'no', 'off'
            self.value = '0'
          else
            self.value = '1'
          end
        end
        self
      end

set_bool_element(idxs, val)

[Source]

    # File tk/lib/tk/variable.rb, line 782
      def set_bool_element(idxs, val)
        if ! val
          val = '0'
        else
          case val.to_s.downcase
          when 'false', '0', 'no', 'off'
            val = '0'
          else
            val = '1'
          end
        end
        if idxs.kind_of?(Array)
          self[*idxs]=val
        else
          self[idxs]=val
        end
        self
      end

set_bool_element_type(idxs, val)

[Source]

    # File tk/lib/tk/variable.rb, line 806
      def set_bool_element_type(idxs, val)
        self.set_default_element_value_type(idxs, :bool)
        self.set_bool_element(idxs, val)
      end

set_bool_type(val)

[Source]

    # File tk/lib/tk/variable.rb, line 800
      def set_bool_type(val)
        @type = :bool
        self.bool=(val)
        self
      end

set_default_element_value_type(idxs, type)

[Source]

    # File tk/lib/tk/variable.rb, line 212
      def set_default_element_value_type(idxs, type)
        _set_default_value_type_core(type, idxs)
        self
      end

set_default_value(val)

[Source]

    # File tk/lib/tk/variable.rb, line 113
      def set_default_value(val)
        @def_default = :val
        @default_val = val
        self
      end

set_default_value_type(type)

[Source]

    # File tk/lib/tk/variable.rb, line 206
      def set_default_value_type(type)
        _set_default_value_type_core(type, nil)
        self
      end

set_element_value(idxs, val)

[Source]

    # File tk/lib/tk/variable.rb, line 681
      def set_element_value(idxs, val)
        if idxs.kind_of?(Array)
          self[*idxs]=val
        else
          self[idxs]=val
        end
        self
      end

set_element_value_type(idxs, val)

[Source]

    # File tk/lib/tk/variable.rb, line 698
      def set_element_value_type(idxs, val)
        self.set_default_element_value_type(idxs, val.class)
        if idxs.kind_of?(Array)
          self[*idxs]=val
        else
          self[idxs]=val
        end
        self
      end

set_list(val)

[Source]

    # File tk/lib/tk/variable.rb, line 1010
      def set_list(val)
        case val
        when Array
          self.value=(val)
        when TkVariable
          self.value=(val.list)
        else
          raise ArgumentError, "Array is expected"
        end
        self
      end

set_list_element(idxs, val)

[Source]

    # File tk/lib/tk/variable.rb, line 1026
      def set_list_element(idxs, val)
        case val
        when Array
          val
        when TkVariable
          val = val.list
        else
          raise ArgumentError, "Array is expected"
        end
        if idxs.kind_of?(Array)
          self[*idxs]=val
        else
          self[idxs]=val
        end
        self
      end

set_list_element_type(idxs, val)

[Source]

    # File tk/lib/tk/variable.rb, line 1050
      def set_list_element_type(idxs, val)
        self.set_default_element_value_type(idxs, :list)
        self.set_list_element(idxs, val)
      end

set_list_type(val)

[Source]

    # File tk/lib/tk/variable.rb, line 1044
      def set_list_type(val)
        @type = :list
        self.list=(val)
        self
      end

set_numeric(val)

[Source]

    # File tk/lib/tk/variable.rb, line 714
      def set_numeric(val)
        case val
        when Numeric
          self.value=(val)
        when TkVariable
          self.value=(val.numeric)
        else
          raise ArgumentError, "Numeric is expected"
        end
        self
      end

set_numeric_element(idxs, val)

[Source]

    # File tk/lib/tk/variable.rb, line 726
      def set_numeric_element(idxs, val)
        case val
        when Numeric
          val
        when TkVariable
          val = val.numeric
        else
          raise ArgumentError, "Numeric is expected"
        end
        if idxs.kind_of?(Array)
          self[*idxs]=val
        else
          self[idxs]=val
        end
        self
      end

set_numeric_element_type(idxs, val)

[Source]

    # File tk/lib/tk/variable.rb, line 748
      def set_numeric_element_type(idxs, val)
        self.set_default_element_value_type(idxs, :numeric)
        self.set_numeric_element(idxs, val)
      end

set_numeric_type(val)

[Source]

    # File tk/lib/tk/variable.rb, line 742
      def set_numeric_type(val)
        @type = :numeric
        self.numeric=(val)
        self
      end

set_numlist(val)

Alias for set_list

set_numlist_element(idxs, val)

Alias for set_list_element

set_numlist_element_type(idxs, val)

[Source]

    # File tk/lib/tk/variable.rb, line 1060
      def set_numlist_element_type(idxs, val)
        self.set_default_element_value_type(idxs, :numlist)
        self.set_numlist_element(idxs, val)
      end

set_numlist_type(val)

[Source]

    # File tk/lib/tk/variable.rb, line 1054
      def set_numlist_type(val)
        @type = :numlist
        self.numlist=(val)
        self
      end

set_procedure(cmd)

[Source]

    # File tk/lib/tk/variable.rb, line 883
      def set_procedure(cmd)
        self.value = cmd
        self
      end

set_procedure_element(idxs, cmd)

[Source]

    # File tk/lib/tk/variable.rb, line 888
      def set_procedure_element(idxs, cmd)
        cmd = cmd._value if cmd.kind_of?(TkVariable)
        if idxs.kind_of?(Array)
          self[*idxs]=cmd
        else
          self[idxs]=cmd
        end
        self
      end

set_procedure_element_type(idxs, cmd)

[Source]

    # File tk/lib/tk/variable.rb, line 903
      def set_procedure_element_type(idxs, cmd)
        self.set_default_element_value_type(idxs, :procedure)
        self.set_proceure_element(idxs, cmd)
      end

set_procedure_type(cmd)

[Source]

    # File tk/lib/tk/variable.rb, line 897
      def set_procedure_type(cmd)
        @type = :procedure
        self.procedure=(cmd)
        self
      end

set_string(val)

[Source]

    # File tk/lib/tk/variable.rb, line 933
      def set_string(val)
        val = val._value if val.kind_of?(TkVariable)
        self.value=val
        self
      end

set_string_element(idxs, val)

[Source]

    # File tk/lib/tk/variable.rb, line 939
      def set_string_element(idxs, val)
        val = val._value if val.kind_of?(TkVariable)
        if idxs.kind_of?(Array)
          self[*idxs]=val
        else
          self[idxs]=val
        end
        self
      end

set_string_element_type(idxs, val)

[Source]

    # File tk/lib/tk/variable.rb, line 954
      def set_string_element_type(idxs, val)
        self.set_default_element_value_type(idxs, :string)
        self.set_string_element(idxs, val)
      end

set_string_type(val)

[Source]

    # File tk/lib/tk/variable.rb, line 948
      def set_string_type(val)
        @type = :string
        self.string=(val)
        self
      end

set_symbol(val)

[Source]

    # File tk/lib/tk/variable.rb, line 967
      def set_symbol(val)
        val = val._value if val.kind_of?(TkVariable)
        self.value=val
        self
      end

set_symbol_element(idxs, val)

[Source]

    # File tk/lib/tk/variable.rb, line 973
      def set_symbol_element(idxs, val)
        val = val._value if val.kind_of?(TkVariable)
        if idxs.kind_of?(Array)
          self[*idxs]=val
        else
          self[idxs]=val
        end
        self
      end

set_symbol_element_type(idxs, val)

[Source]

    # File tk/lib/tk/variable.rb, line 988
      def set_symbol_element_type(idxs, val)
        self.set_default_element_value_type(idxs, :symbol)
        self.set_symbol_element(idxs, val)
      end

set_symbol_type(val)

[Source]

    # File tk/lib/tk/variable.rb, line 982
      def set_symbol_type(val)
        @type = :symbol
        self.value=(val)
        self
      end

set_value(val)

[Source]

    # File tk/lib/tk/variable.rb, line 676
      def set_value(val)
        self.value = val
        self
      end

set_value_type(val)

[Source]

    # File tk/lib/tk/variable.rb, line 690
      def set_value_type(val)
        self.default_value_type = val.class
        self.value = val
        self
      end

set_variable(var)

[Source]

    # File tk/lib/tk/variable.rb, line 818
      def set_variable(var)
        var = var.id if var.kind_of?(TkVariable)
        self.value = var
        self
      end

set_variable_element(idxs, var)

[Source]

    # File tk/lib/tk/variable.rb, line 824
      def set_variable_element(idxs, var)
        var = var.id if var.kind_of?(TkVariable)
        if idxs.kind_of?(Array)
          self[*idxs]=var
        else
          self[idxs]=var
        end
        self
      end

set_variable_element_type(idxs, var)

[Source]

    # File tk/lib/tk/variable.rb, line 840
      def set_variable_element_type(idxs, var)
        self.set_default_element_value_type(idxs, :variable)
        self.set_variable_element(idxs, var)
      end

set_variable_type(var)

[Source]

    # File tk/lib/tk/variable.rb, line 833
      def set_variable_type(var)
        @type = :variable
        var = var.id if var.kind_of?(TkVariable)
        self.value = var
        self
      end

set_window(win)

[Source]

    # File tk/lib/tk/variable.rb, line 851
      def set_window(win)
        win = win._value if win.kind_of?(TkVariable)
        self.value = win
        self
      end

set_window_element(idxs, win)

[Source]

    # File tk/lib/tk/variable.rb, line 857
      def set_window_element(idxs, win)
        win = win._value if win.kind_of?(TkVariable)
        if idxs.kind_of?(Array)
          self[*idxs]=win
        else
          self[idxs]=win
        end
        self
      end

set_window_element_type(idxs, win)

[Source]

    # File tk/lib/tk/variable.rb, line 872
      def set_window_element_type(idxs, win)
        self.set_default_element_value_type(idxs, :window)
        self.set_window_element(idxs, win)
      end

set_window_type(win)

[Source]

    # File tk/lib/tk/variable.rb, line 866
      def set_window_type(win)
        @type = :window
        self.window=(win)
        self
      end

size()

[Source]

    # File tk/lib/tk/variable.rb, line 424
      def size
        INTERP._invoke_without_enc('global', @id)
        TkComm.number(INTERP._invoke_without_enc('array', 'size', @id))
      end

string()

Alias for to_s

string=(val)

Alias for set_string

string_element(*idxs)

[Source]

    # File tk/lib/tk/variable.rb, line 930
      def string_element(*idxs)
        _element_value(*idxs)
      end

string_type=(val)

Alias for set_string_type

symbol()

Alias for to_sym

symbol=(val)

Alias for set_symbol

symbol_element(*idxs)

Alias for element_to_sym

symbol_type=(val)

Alias for set_symbol_type

thread_tkwait()

[Source]

    # File tk/lib/tk/variable.rb, line 377
      def thread_tkwait
        wait(true, true)
      end

thread_wait(check_root = false)

[Source]

    # File tk/lib/tk/variable.rb, line 368
      def thread_wait(check_root = false)
        wait(true, check_root)
      end

tkwait(on_thread = true)

[Source]

    # File tk/lib/tk/variable.rb, line 371
      def tkwait(on_thread = true)
        wait(on_thread, true)
      end

to_a()

Alias for list

to_eval()

[Source]

    # File tk/lib/tk/variable.rb, line 1254
      def to_eval
        @id
      end

to_f()

[Source]

    # File tk/lib/tk/variable.rb, line 915
      def to_f
        number(_value).to_f
      end

to_i()

[Source]

    # File tk/lib/tk/variable.rb, line 908
      def to_i
        number(_value).to_i
      end

to_s()

[Source]

    # File tk/lib/tk/variable.rb, line 922
      def to_s
        #string(value).to_s
        _value
      end

to_sym()

[Source]

    # File tk/lib/tk/variable.rb, line 959
      def to_sym
        _value.intern
      end

trace(opts, cmd = Proc.new)

[Source]

    # File tk/lib/tk/variable.rb, line 1269
      def trace(opts, cmd = Proc.new)
        @trace_var = [] if @trace_var == nil
        #opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('')
        opts = opts.to_s
        opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('')
        @trace_var.unshift([opts,cmd])
        if @trace_opts == nil
          TkVar_CB_TBL[@id] = self
          @trace_opts = opts.dup
          Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts,
                                 'rb_var ' << @id)
    ??
        else
          newopts = @trace_opts.dup
          #opts.each_byte{|c| newopts += c.chr unless newopts.index(c)}
          opts.each_byte{|c| newopts.concat(c.chr) unless newopts.index(c)}
          if newopts != @trace_opts
            Tk.tk_call_without_enc('trace', 'vdelete', @id, @trace_opts,
                                   'rb_var ' << @id)
            @trace_opts.replace(newopts)
            Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts,
                                   'rb_var ' << @id)
    ??
          end
        end
        self
      end

trace_callback(elem, op)

[Source]

    # File tk/lib/tk/variable.rb, line 1258
      def trace_callback(elem, op)
        if @trace_var.kind_of? Array
          @trace_var.each{|m,e| e.call(self,elem,op) if m.index(op)}
        end
        if elem.kind_of?(String) && elem != ''
          if @trace_elem.kind_of?(Hash) && @trace_elem[elem].kind_of?(Array)
            @trace_elem[elem].each{|m,e| e.call(self,elem,op) if m.index(op)}
          end
        end
      end

trace_element(elem, opts, cmd = Proc.new)

[Source]

    # File tk/lib/tk/variable.rb, line 1322
      def trace_element(elem, opts, cmd = Proc.new)
        if @elem
          fail(RuntimeError,
               "invalid for a TkVariable which denotes an element of Tcl's array")
        end
        @trace_elem = {} if @trace_elem == nil
        @trace_elem[elem] = [] if @trace_elem[elem] == nil
        opts = opts.to_s
        opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('')
        @trace_elem[elem].unshift([opts,cmd])
        if @trace_opts == nil
          TkVar_CB_TBL[@id] = self
          @trace_opts = opts.dup
          Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts,
                                 'rb_var ' << @id)
    ??
        else
          newopts = @trace_opts.dup
          # opts.each_byte{|c| newopts += c.chr unless newopts.index(c)}
          opts.each_byte{|c| newopts.concat(c.chr) unless newopts.index(c)}
          if newopts != @trace_opts
            Tk.tk_call_without_enc('trace', 'vdelete', @id, @trace_opts,
                                   'rb_var ' << @id)
            @trace_opts.replace(newopts)
            Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts,
                                   'rb_var ' << @id)
    ??
          end
        end
        self
      end

trace_vdelete(opts,cmd)

[Source]

    # File tk/lib/tk/variable.rb, line 1395
      def trace_vdelete(opts,cmd)
        return self unless @trace_var.kind_of? Array
        opts = opts.to_s
        opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('')
        idx = -1
        newopts = ''
        @trace_var.each_with_index{|e,i|
          if idx < 0 && e[0] == opts && e[1] == cmd
            idx = i
            next
          end
          # e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)}
          e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c)}
        }
        if idx >= 0
          @trace_var.delete_at(idx)
        else
          return self
        end

        @trace_elem.each{|elem|
          @trace_elem[elem].each{|e|
            # e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)}
            e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c)}
          }
        }

        newopts = newopts.to_s
        newopts = ['r','w','u'].find_all{|c| newopts.index(c)}.join('')
        if newopts != @trace_opts
          Tk.tk_call_without_enc('trace', 'vdelete', @id, @trace_opts,
                                 'rb_var ' << @id)
    ??
          @trace_opts.replace(newopts)
          if @trace_opts != ''
            Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts,
                                   'rb_var ' << @id)
    ??
          end
        end

        self
      end

trace_vdelete_for_element(elem,opts,cmd)

[Source]

    # File tk/lib/tk/variable.rb, line 1459
      def trace_vdelete_for_element(elem,opts,cmd)
        if @elem
          fail(RuntimeError,
               "invalid for a TkVariable which denotes an element of Tcl's array")
        end
        return self unless @trace_elem.kind_of? Hash
        return self unless @trace_elem[elem].kind_of? Array
        opts = opts.to_s
        opts = ['r','w','u'].find_all{|c| opts.index(c)}.join('')
        idx = -1
        @trace_elem[elem].each_with_index{|e,i|
          if idx < 0 && e[0] == opts && e[1] == cmd
            idx = i
            next
          end
        }
        if idx >= 0
          @trace_elem[elem].delete_at(idx)
        else
          return self
        end

        newopts = ''
        @trace_var.each{|e|
          # e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)}
          e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c)}
        }
        @trace_elem.each{|elem|
          @trace_elem[elem].each{|e|
            # e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)}
            e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c)}
          }
        }

        newopts = newopts.to_s
        newopts = ['r','w','u'].find_all{|c| newopts.index(c)}.join('')
        if newopts != @trace_opts
          Tk.tk_call_without_enc('trace', 'vdelete', @id, @trace_opts,
                                 'rb_var ' << @id)
    ??
          @trace_opts.replace(newopts)
          if @trace_opts != ''
            Tk.tk_call_without_enc('trace', 'variable', @id, @trace_opts,
                                   'rb_var ' << @id)
    ??
          end
        end

        self
      end

trace_vinfo()

[Source]

    # File tk/lib/tk/variable.rb, line 1380
      def trace_vinfo
        return [] unless @trace_var
        @trace_var.dup
      end

undef_default()

[Source]

    # File tk/lib/tk/variable.rb, line 125
      def undef_default
        @default_val = nil
        @def_default = false
        self
      end

unset(*elems)

[Source]

    # File tk/lib/tk/variable.rb, line 648
      def unset(*elems)
        if elems.empty?
          INTERP._eval(Kernel.format('global %s; unset %s', @id, @id))
          #INTERP._eval(Kernel.format('unset %s', @id))
          #INTERP._eval('unset ' + @id)
        else
          index = elems.collect{|idx| _get_eval_string(idx, true)}.join(',')
          INTERP._eval(Kernel.format('global %s; unset %s(%s)', @id, @id, index))
          #INTERP._eval(Kernel.format('global %s; unset %s(%s)',
          #                           @id, @id, _get_eval_string(elem)))
          #INTERP._eval(Kernel.format('unset %s(%s)', @id, tk_tcl2ruby(elem)))
          #INTERP._eval('unset ' + @id + '(' + _get_eval_string(elem) + ')')
        end
      end

unset(*elems)

[Source]

    # File tk/lib/tk/variable.rb, line 528
      def unset(*elems)
        if elems.empty?
          INTERP._unset_global_var(@id)
        else
          index = elems.collect{|idx| _get_eval_string(idx, true)}.join(',')
          INTERP._unset_global_var2(@id, index)
        end
      end

update(hash)

[Source]

    # File tk/lib/tk/variable.rb, line 437
      def update(hash)
        if (is_scalar?)
          fail RuntimeError, 'cannot update a scalar variable'
        end
        hash.each{|k,v| self[k] = v}
        self
      end

value()

[Source]

    # File tk/lib/tk/variable.rb, line 668
      def value
        _to_default_type(_value)
      end

value=(val)

[Source]

    # File tk/lib/tk/variable.rb, line 561
      def value=(val)
        val = val._value if !@type && @type != :variable && val.kind_of?(TkVariable)
        begin
          #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._eval(Kernel.format('set %s %s', @id, s))
          #_fromUTF8(INTERP._invoke_without_enc('set', @id, _toUTF8(s)))
        rescue
          if INTERP._eval(Kernel.format('global %s; array exists %s',
                                @id, @id)) != "1"
          #if INTERP._eval(Kernel.format('array exists %s', @id)) != "1"
          #if INTERP._invoke_without_enc('array', 'exists', @id) != "1"
            fail
          else
            if val == []
              INTERP._eval(Kernel.format('global %s; unset %s; set %s(0) 0; unset %s(0)', @id, @id, @id, @id))
              #INTERP._eval(Kernel.format('unset %s; set %s(0) 0; unset %s(0)',
              #                          @id, @id, @id))
              #INTERP._invoke_without_enc('unset', @id)
              #INTERP._invoke_without_enc('set', @id+'(0)', 0)
              #INTERP._invoke_without_enc('unset', @id+'(0)')
            elsif val.kind_of?(Array)
              a = []
              val.each_with_index{|e,i| a.push(i); a.push(array2tk_list(e, true))}
              #s = '"' + a.join(" ").gsub(/[\[\]$"]/, '\\\\\&') + '"'
              s = '"' + a.join(" ").gsub(/[\[\]$"\\]/, '\\\\\&') + '"'
              INTERP._eval(Kernel.format('global %s; unset %s; array set %s %s',
                                         @id, @id, @id, s))
              #INTERP._eval(Kernel.format('unset %s; array set %s %s',
              #                          @id, @id, s))
              #INTERP._invoke_without_enc('unset', @id)
              #_fromUTF8(INTERP._invoke_without_enc('array','set', @id, _toUTF8(s)))
            elsif  val.kind_of?(Hash)
              #s = '"' + val.to_a.collect{|e| array2tk_list(e)}.join(" ")           #                      .gsub(/[\[\]$"]/, '\\\\\&') + '"'
              s = '"' + val.to_a.collect{|e| array2tk_list(e, true)}.join(" ")\
                                    .gsub(/[\[\]$\\"]/, '\\\\\&') + '"'
              INTERP._eval(Kernel.format('global %s; unset %s; array set %s %s',
                                         @id, @id, @id, s))
              #INTERP._eval(Kernel.format('unset %s; array set %s %s',
              #                          @id, @id, s))
              #INTERP._invoke_without_enc('unset', @id)
              #_fromUTF8(INTERP._invoke_without_enc('array','set', @id, _toUTF8(s)))
            else
              fail
            end
          end
        end
      end

value=(val)

[Source]

    # File tk/lib/tk/variable.rb, line 466
      def value=(val)
        val = val._value if !@type && @type != :variable && val.kind_of?(TkVariable)
        if val.kind_of?(Hash)
          self.clear
          val.each{|k, v|
            #INTERP._set_global_var2(@id, _toUTF8(_get_eval_string(k)),
            #                       _toUTF8(_get_eval_string(v)))
            INTERP._set_global_var2(@id, _get_eval_string(k, true),
                                    _get_eval_string(v, true))
          }
          self.value
    #    elsif val.kind_of?(Array)
    ??
    #      _fromUTF8(INTERP._set_global_var(@id, array2tk_list(val, true)))
        else
          #_fromUTF8(INTERP._set_global_var(@id, _toUTF8(_get_eval_string(val))))
          _fromUTF8(INTERP._set_global_var(@id, _get_eval_string(val, true)))
        end
      end

value_type=(val)

Alias for set_value_type

variable()

[Source]

    # File tk/lib/tk/variable.rb, line 811
      def variable
        # keeps a Tcl's variable name
        TkVarAccess.new(self._value)
      end

variable=(var)

Alias for set_variable

variable_element(*idxs)

[Source]

    # File tk/lib/tk/variable.rb, line 815
      def variable_element(*idxs)
        TkVarAccess.new(_element_value(*idxs))
      end

variable_type=(var)

Alias for set_variable_type

wait(on_thread = false, check_root = false)

[Source]

    # File tk/lib/tk/variable.rb, line 346
      def wait(on_thread = false, check_root = false)
        if $SAFE >= 4
          fail SecurityError, "can't wait variable at $SAFE >= 4"
        end
        on_thread &= (Thread.list.size != 1)
        if on_thread
          if check_root
            INTERP._thread_tkwait('variable', @id)
          else
            INTERP._thread_vwait(@id)
          end
        else
          if check_root
            INTERP._invoke_without_enc('tkwait', 'variable', @id)
          else
            INTERP._invoke_without_enc('vwait', @id)
          end
        end
      end

window()

[Source]

    # File tk/lib/tk/variable.rb, line 845
      def window
        TkComm.window(self._value)
      end

window=(win)

Alias for set_window

window_element(*idxs)

[Source]

    # File tk/lib/tk/variable.rb, line 848
      def window_element(*idxs)
        TkComm.window(_element_value(*idxs))
      end

window_type=(win)

Alias for set_window_type

zero?()

[Source]

    # File tk/lib/tk/variable.rb, line 1226
      def zero?
        numeric.zero?
      end

|(other)

[Source]

    # File tk/lib/tk/variable.rb, line 1148
      def |(other)
        if other.kind_of?(Array)
          self.to_a | other.to_a
        else
          self.to_i | other.to_i
        end
      end

[Validate]