From 85b326ac4207698bbab25c3679661cfe6e0b4e3d Mon Sep 17 00:00:00 2001 From: nagai Date: Sat, 3 Oct 2009 20:39:54 +0000 Subject: * ext/tk/lib/tk/variable.rb: add TkVariable#to_hash,to_proc,to_int,to_str,to_ary git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25218 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/lib/tk/variable.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'ext/tk/lib') diff --git a/ext/tk/lib/tk/variable.rb b/ext/tk/lib/tk/variable.rb index 6fc2ffdf2f..ee60fcfc6c 100644 --- a/ext/tk/lib/tk/variable.rb +++ b/ext/tk/lib/tk/variable.rb @@ -694,6 +694,14 @@ end self end + def to_hash + hash = {} + self.keys.each{|k| + hash[k] = self[k] + } + hash + end + def set_element_value(idxs, val) if idxs.kind_of?(Array) self[*idxs]=val @@ -921,9 +929,20 @@ end self.set_proceure_element(idxs, cmd) end + def to_proc + cmd = self.procedure + if cmd.respond_to?(:call) + cmd + else + # cmd is a String + cmd.to_sym.to_proc + end + end + def to_i number(_value).to_i end + alias to_int to_i def element_to_i(*idxs) number(_element_value(*idxs)).to_i end @@ -940,6 +959,7 @@ end _value end alias string to_s + alias to_str to_s def element_to_s(*idxs) _element_value(*idxs) end @@ -1011,6 +1031,7 @@ end tk_split_simplelist(_value) end alias to_a list + alias to_ary list def list_element(*idxs) tk_split_simplelist(_element_value(*idxs)) end -- cgit v1.2.3