Class: Tk::Variable

Inherits:
Object show all
Defined in:
lib/ffi-tk/variable.rb

Overview

This class is used for communication of variables with Tcl.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value = None) ⇒ Variable

Returns a new instance of Variable.



6
7
8
9
10
# File 'lib/ffi-tk/variable.rb', line 6

def initialize(name, value = None)
  @name = name.freeze
  @tcl_name = "$#{name}".freeze
  set(value) unless None == value
end

Instance Attribute Details

#bytesizeObject (readonly)

Returns the value of attribute bytesize.



4
5
6
# File 'lib/ffi-tk/variable.rb', line 4

def bytesize
  @bytesize
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/ffi-tk/variable.rb', line 4

def name
  @name
end

#tcl_nameObject (readonly)

Returns the value of attribute tcl_name.



4
5
6
# File 'lib/ffi-tk/variable.rb', line 4

def tcl_name
  @tcl_name
end

Instance Method Details

#getObject



12
13
14
15
16
# File 'lib/ffi-tk/variable.rb', line 12

def get
  Tk.execute('set', name)
rescue RuntimeError
  raise NameError, "can't read %p: no such variable" % [name]
end

#set(value) ⇒ Object



18
19
20
# File 'lib/ffi-tk/variable.rb', line 18

def set(value)
  Tk.execute_only('set', name, value)
end

#to_booleanObject



38
39
40
# File 'lib/ffi-tk/variable.rb', line 38

def to_boolean
  get.to_boolean
end

#to_fObject



42
43
44
# File 'lib/ffi-tk/variable.rb', line 42

def to_f
  get.to_f
end

#to_iObject



34
35
36
# File 'lib/ffi-tk/variable.rb', line 34

def to_i
  get.to_i
end

#to_sObject



30
31
32
# File 'lib/ffi-tk/variable.rb', line 30

def to_s
  get.to_s
end

#to_tclObject



26
27
28
# File 'lib/ffi-tk/variable.rb', line 26

def to_tcl
  TclString.new(name)
end

#unsetObject



22
23
24
# File 'lib/ffi-tk/variable.rb', line 22

def unset
  Tk.execute_only('unset', name)
end