Extended maintenance of Ruby 1.9.3 ended on February 23, 2015. Read more
# File tk/lib/tk/namespace.rb, line 291
def self.children(*args)
# args ::= [<namespace>] [<pattern>]
# <pattern> must be glob-style pattern
tk_split_simplelist(tk_call('namespace', 'children', *args)).collect{|ns|
# ns is fullname
Tk_Namespace_ID_TBL.mutex.synchronize{
if Tk_Namespace_ID_TBL.key?(ns)
Tk_Namespace_ID_TBL[ns]
else
ns
end
}
}
end
# File tk/lib/tk/namespace.rb, line 309
def self.code(script = Proc.new)
TkNamespace.new('').code(script)
end
# File tk/lib/tk/namespace.rb, line 360
def self.current
ns = self.current_path
Tk_Namespace_ID_TBL.mutex.synchronize{
if Tk_Namespace_ID_TBL.key?(ns)
Tk_Namespace_ID_TBL[ns]
else
ns
end
}
end
# File tk/lib/tk/namespace.rb, line 353
def self.current_path
tk_call('namespace', 'current')
end
# File tk/lib/tk/namespace.rb, line 377
def self.delete(*ns_list)
tk_call('namespace', 'delete', *ns_list)
ns_list.each{|ns|
Tk_Namespace_ID_TBL.mutex.synchronize{
if ns.kind_of?(TkNamespace)
Tk_Namespace_ID_TBL.delete(ns.path)
else
Tk_Namespace_ID_TBL.delete(ns.to_s)
end
}
}
end
# File tk/lib/tk/namespace.rb, line 403
def self.ensemble_configinfo(cmd, slot = nil)
if slot
tk_call('namespace', 'ensemble', 'configure', cmd, '-' + slot.to_s)
else
inf = {}
Hash(*tk_split_simplelist(tk_call('namespace', 'ensemble', 'configure', cmd))).each{|k, v| inf[k[1..-1]] = v}
inf
end
end
# File tk/lib/tk/namespace.rb, line 396
def self.ensemble_configure(cmd, slot, value=None)
if slot.kind_of?(Hash)
tk_call('namespace', 'ensemble', 'configure', cmd, *hash_kv(slot))
else
tk_call('namespace', 'ensemble', 'configure', cmd, '-'+slot.to_s, value)
end
end
# File tk/lib/tk/namespace.rb, line 393
def self.ensemble_create(*keys)
tk_call('namespace', 'ensemble', 'create', *hash_kv(keys))
end
# File tk/lib/tk/namespace.rb, line 412
def self.ensemble_exist?(cmd)
bool(tk_call('namespace', 'ensemble', 'exists', cmd))
end
# File tk/lib/tk/namespace.rb, line 416
def self.eval(namespace, cmd = Proc.new, *args)
#tk_call('namespace', 'eval', namespace, cmd, *args)
TkNamespace.new(namespace).eval(cmd, *args)
end
# File tk/lib/tk/namespace.rb, line 438
def self.exist?(ns)
bool(tk_call('namespace', 'exists', ns))
end
# File tk/lib/tk/namespace.rb, line 445
def self.export(*patterns)
tk_call('namespace', 'export', *patterns)
end
# File tk/lib/tk/namespace.rb, line 448
def self.export_with_clear(*patterns)
tk_call('namespace', 'export', '-clear', *patterns)
end
# File tk/lib/tk/namespace.rb, line 468
def self.force_import(*patterns)
tk_call('namespace', 'import', '-force', *patterns)
end
# File tk/lib/tk/namespace.rb, line 458
def self.forget(*patterns)
tk_call('namespace', 'forget', *patterns)
end
# File tk/lib/tk/namespace.rb, line 503
def self.get_path
tk_call('namespace', 'path')
end
# File tk/lib/tk/namespace.rb, line 528
def self.get_unknown_handler
tk_tcl2ruby(tk_call('namespace', 'unknown'))
end
# File tk/lib/tk/namespace.rb, line 29
def TkNamespace.id2obj(id)
Tk_Namespace_ID_TBL.mutex.synchronize{
Tk_Namespace_ID_TBL[id]? Tk_Namespace_ID_TBL[id]: id
}
end
# File tk/lib/tk/namespace.rb, line 465
def self.import(*patterns)
tk_call('namespace', 'import', *patterns)
end
# File tk/lib/tk/namespace.rb, line 478
def self.inscope(namespace, script, *args)
tk_call('namespace', 'inscope', namespace, script, *args)
end
# File tk/lib/tk/namespace.rb, line 245
def initialize(name = nil, parent = nil)
unless name
Tk_Namespace_ID.mutex.synchronize{
# name = Tk_Namespace_ID.join('')
name = Tk_Namespace_ID.join(TkCore::INTERP._ip_id_)
Tk_Namespace_ID[1].succ!
}
end
name = __tk_call('namespace', 'current') if name == ''
if parent
if parent =~ /^::/
if name =~ /^::/
@fullname = parent + name
else
@fullname = parent +'::'+ name
end
else
ancestor = __tk_call('namespace', 'current')
ancestor = '' if ancestor == '::'
if name =~ /^::/
@fullname = ancestor + '::' + parent + name
else
@fullname = ancestor + '::'+ parent +'::'+ name
end
end
else # parent == nil
ancestor = __tk_call('namespace', 'current')
ancestor = '' if ancestor == '::'
if name =~ /^::/
@fullname = name
else
@fullname = ancestor + '::' + name
end
end
@path = @fullname
@parent = __tk_call('namespace', 'qualifiers', @fullname)
@name = __tk_call('namespace', 'tail', @fullname)
# create namespace
__tk_call('namespace', 'eval', @fullname, '')
Tk_Namespace_ID_TBL.mutex.synchronize{
Tk_Namespace_ID_TBL[@fullname] = self
}
end
# File tk/lib/tk/namespace.rb, line 485
def self.origin(cmd)
tk_call('namespace', 'origin', cmd)
end
# File tk/lib/tk/namespace.rb, line 489
def self.parent(namespace=None)
ns = tk_call('namespace', 'parent', namespace)
Tk_Namespace_ID_TBL.mutex.synchronize{
if Tk_Namespace_ID_TBL.key?(ns)
Tk_Namespace_ID_TBL[ns]
else
ns
end
}
end
# File tk/lib/tk/namespace.rb, line 513
def self.qualifiers(str)
tk_call('namespace', 'qualifiers', str)
end
# File tk/lib/tk/namespace.rb, line 506
def self.set_path(*namespace_list)
tk_call('namespace', 'path', array2tk_list(namespace_list))
end
# File tk/lib/tk/namespace.rb, line 531
def self.set_unknown_handler(cmd = Proc.new)
tk_call('namespace', 'unknown', cmd)
end
# File tk/lib/tk/namespace.rb, line 517
def self.tail(str)
tk_call('namespace', 'tail', str)
end
# File tk/lib/tk/namespace.rb, line 521
def self.upvar(namespace, *var_pairs)
tk_call('namespace', 'upvar', namespace, *(var_pairs.flatten))
end
# File tk/lib/tk/namespace.rb, line 535
def self.which(name)
tk_call('namespace', 'which', name)
end
# File tk/lib/tk/namespace.rb, line 305
def children(pattern=None)
TkNamespace.children(@fullname, pattern)
end
def code(script = Proc.new)
if script.kind_of?(String) cmd = proc{|*args| ScopeArgs.new(@fullname,*args).instance_eval(script)} elsif script.kind_of?(Proc) cmd = proc{|*args| ScopeArgs.new(@fullname,*args).instance_eval(&script)} else fail ArgumentError, "String or Proc is expected" end TkNamespace::NsCode.new(tk_call_without_enc('namespace', 'code', _get_eval_string(cmd, false)))
end
# File tk/lib/tk/namespace.rb, line 325
def code(script = Proc.new)
if script.kind_of?(String)
cmd = proc{|*args|
ret = ScopeArgs.new(@fullname,*args).instance_eval(script)
id = ret.object_id
TkNamespace::Tk_NsCode_RetObjID_TBL[id] = ret
id
}
elsif script.kind_of?(Proc)
cmd = proc{|*args|
if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!!
obj = ScopeArgs.new(@fullname,*args)
ret = obj.instance_exec(obj, &script)
else
ret = ScopeArgs.new(@fullname,*args).instance_eval(&script)
end
id = ret.object_id
TkNamespace::Tk_NsCode_RetObjID_TBL[id] = ret
id
}
else
fail ArgumentError, "String or Proc is expected"
end
TkNamespace::NsCode.new(tk_call_without_enc('namespace', 'code',
_get_eval_string(cmd, false)),
true)
end
# File tk/lib/tk/namespace.rb, line 370
def current_namespace
# ns_tk_call('namespace', 'current')
# @fullname
self
end
# File tk/lib/tk/namespace.rb, line 356
def current_path
@fullname
end
# File tk/lib/tk/namespace.rb, line 389
def delete
TkNamespece.delete(@fullname)
end
def eval(cmd = Proc.new, *args)
#TkNamespace.eval(@fullname, cmd, *args) #ns_tk_call(cmd, *args) code_obj = code(cmd) ret = code_obj.call(*args) # uninstall_cmd(TkCore::INTERP._split_tklist(code_obj.path)[-1]) uninstall_cmd(_fromUTF8(TkCore::INTERP._split_tklist(_toUTF8(code_obj.path))[-1])) tk_tcl2ruby(ret)
end
# File tk/lib/tk/namespace.rb, line 431
def eval(cmd = Proc.new, *args)
code_obj = code(cmd)
ret = code_obj.call(*args)
uninstall_cmd(_fromUTF8(TkCore::INTERP._split_tklist(_toUTF8(code_obj.path))[-1]))
ret
end
# File tk/lib/tk/namespace.rb, line 441
def exist?
TkNamespece.exist?(@fullname)
end
# File tk/lib/tk/namespace.rb, line 451
def export
TkNamespace.export(@fullname)
end
# File tk/lib/tk/namespace.rb, line 454
def export_with_clear
TkNamespace.export_with_clear(@fullname)
end
# File tk/lib/tk/namespace.rb, line 474
def force_import
TkNamespace.force_import(@fullname)
end
# File tk/lib/tk/namespace.rb, line 461
def forget
TkNamespace.forget(@fullname)
end
# File tk/lib/tk/namespace.rb, line 471
def import
TkNamespace.import(@fullname)
end
# File tk/lib/tk/namespace.rb, line 481
def inscope(script, *args)
TkNamespace.inscope(@fullname, script, *args)
end
# File tk/lib/tk/namespace.rb, line 210
def install_cmd(cmd)
lst = tk_split_simplelist(super(cmd), false, false)
if lst[1] =~ /^::/
lst[1] = @fullname
else
lst.insert(1, @fullname)
end
TkCore::INTERP._merge_tklist(*lst)
end
# File tk/lib/tk/namespace.rb, line 499
def parent
tk_call('namespace', 'parent', @fullname)
end
# File tk/lib/tk/namespace.rb, line 509
def set_path
tk_call('namespace', 'path', @fullname)
end
# File tk/lib/tk/namespace.rb, line 223
def tk_call(*args)
#super('namespace', 'eval', @fullname, *args)
args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''}
super('namespace', 'eval', @fullname,
TkCore::INTERP._merge_tklist(*args))
end
# File tk/lib/tk/namespace.rb, line 235
def tk_call_with_enc(*args)
#super('namespace', 'eval', @fullname, *args)
args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''}
super('namespace', 'eval', @fullname,
TkCore::INTERP._merge_tklist(*args))
end
# File tk/lib/tk/namespace.rb, line 229
def tk_call_without_enc(*args)
#super('namespace', 'eval', @fullname, *args)
args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''}
super('namespace', 'eval', @fullname,
TkCore::INTERP._merge_tklist(*args))
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.