# File tk/lib/tk/variable.rb, line 1653 def self.new(name, *args) if name.kind_of?(TkVariable) name.value = args[0] unless args.empty? return name end name = name.to_s v = nil TkVar_ID_TBL.mutex.synchronize{ if v = TkVar_ID_TBL[name] v.value = args[0] unless args.empty? return v else (v = self.allocate).instance_eval{ @id = name TkVar_ID_TBL[@id] = self @var = @id } end } v.instance_eval{ initialize(name, *args) } v end
# File tk/lib/tk/variable.rb, line 1714 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) begin INTERP._invoke_without_enc('global', @id) rescue => e if @id =~ /^(.+)\([^()]+\)$/ # is an element --> varname == $1 INTERP._invoke_without_enc('global', $1) else fail e end end 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
# File tk/lib/tk/variable.rb, line 1678 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 name = name.to_s v = nil TkVar_ID_TBL.mutex.synchronize{ 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 else (v = self.allocate).instance_eval{ @id = name TkVar_ID_TBL[@id] = self @var = @id } end } INTERP._invoke_without_enc('global', name) if args.empty? && INTERP._invoke_without_enc('array', 'exist', name) == '0' v.instance_eval{ initialize(name, {}) } # force creating else v.instance_eval{ initialize(name, *args) } end v end
Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.
If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.
If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.
If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.