Class: Tk::Variable
- Includes:
- Comparable
- Defined in:
- lib/ffi-tk/variable.rb
Overview
This class is used for communication of variables with Tcl.
Instance Attribute Summary collapse
-
#bytesize ⇒ Object
readonly
Returns the value of attribute bytesize.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#tcl_name ⇒ Object
readonly
Returns the value of attribute tcl_name.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #get ⇒ Object
-
#initialize(name, value = None) ⇒ Variable
constructor
A new instance of Variable.
- #set(value) ⇒ Object
- #to_boolean ⇒ Object
- #to_f ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
- #to_tcl ⇒ Object
- #unset ⇒ Object
Constructor Details
Instance Attribute Details
#bytesize ⇒ Object (readonly)
Returns the value of attribute bytesize.
7 8 9 |
# File 'lib/ffi-tk/variable.rb', line 7 def bytesize @bytesize end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/ffi-tk/variable.rb', line 7 def name @name end |
#tcl_name ⇒ Object (readonly)
Returns the value of attribute tcl_name.
7 8 9 |
# File 'lib/ffi-tk/variable.rb', line 7 def tcl_name @tcl_name end |
Instance Method Details
#<=>(other) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/ffi-tk/variable.rb', line 59 def <=>(other) case other when self.class get <=> other.get else get <=> other end end |
#get ⇒ Object
15 16 17 18 19 |
# File 'lib/ffi-tk/variable.rb', line 15 def get Tk.execute('set', name) rescue RuntimeError raise NameError, "can't read %p: no such variable" % [name] end |
#set(value) ⇒ Object
21 22 23 |
# File 'lib/ffi-tk/variable.rb', line 21 def set(value) Tk.execute_only('set', name, value) end |
#to_boolean ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ffi-tk/variable.rb', line 41 def to_boolean got = get if got.respond_to?(:to_boolean) got.to_boolean elsif got == '0' false elsif got == '1' true else got end end |
#to_f ⇒ Object
55 56 57 |
# File 'lib/ffi-tk/variable.rb', line 55 def to_f get.to_f end |
#to_i ⇒ Object
37 38 39 |
# File 'lib/ffi-tk/variable.rb', line 37 def to_i get.to_i end |
#to_s ⇒ Object
33 34 35 |
# File 'lib/ffi-tk/variable.rb', line 33 def to_s get.to_s end |
#to_tcl ⇒ Object
29 30 31 |
# File 'lib/ffi-tk/variable.rb', line 29 def to_tcl TclString.new(name) end |
#unset ⇒ Object
25 26 27 |
# File 'lib/ffi-tk/variable.rb', line 25 def unset Tk.execute_only('unset', name) end |