[前][次][番号順一覧][スレッド一覧]

ruby-changes:13445

From: nagai <ko1@a...>
Date: Sun, 4 Oct 2009 05:40:15 +0900 (JST)
Subject: [ruby-changes:13445] Ruby:r25218 (trunk): * ext/tk/lib/tk/variable.rb: add TkVariable#to_hash,to_proc,to_int,to_str,to_ary

nagai	2009-10-04 05:39:54 +0900 (Sun, 04 Oct 2009)

  New Revision: 25218

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25218

  Log:
    * ext/tk/lib/tk/variable.rb: add TkVariable#to_hash,to_proc,to_int,to_str,to_ary

  Modified files:
    trunk/ChangeLog
    trunk/ext/tk/lib/tk/variable.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 25217)
+++ ChangeLog	(revision 25218)
@@ -1,3 +1,8 @@
+Sun Oct  4 05:34:34 2009  Hidetoshi NAGAI  <nagai@a...>
+
+	* ext/tk/lib/tk/variable.rb: add TkVariable#to_hash,to_proc,to_int,
+	  to_str,to_ary
+
 Sun Oct  4 00:59:52 2009  Takeyuki FUJIOKA  <xibbar@r...>
 
 	* lib/cgi/core.rb: fix command-line option of
Index: ext/tk/lib/tk/variable.rb
===================================================================
--- ext/tk/lib/tk/variable.rb	(revision 25217)
+++ ext/tk/lib/tk/variable.rb	(revision 25218)
@@ -694,6 +694,14 @@
     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 @@
     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 @@
     _value
   end
   alias string to_s
+  alias to_str to_s
   def element_to_s(*idxs)
     _element_value(*idxs)
   end
@@ -1011,6 +1031,7 @@
     tk_split_simplelist(_value)
   end
   alias to_a list
+  alias to_ary list
   def list_element(*idxs)
     tk_split_simplelist(_element_value(*idxs))
   end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]