From: email55555 email55555 Date: 2004-12-09T09:43:05+09:00 Subject: Re: binding question I am learning Tk from the book "Practical Programming in Tcl and Tk". I try to translate the book's examples from Tcl to Ruby. (as exercice for myself) Here is one of kind example: (TCL) foreach name {one two three four five} { label .$name -text $name -bg white pack .$name -side top } pack .five -before .one Ruby version: (Of course, there are many ways to write it) %w[one two three four five].each {|name| ??? = TkLabel.new(:text=>name, :bg=>'white') { pack(:side=>:top) } } Tk.pack five, :before=>one ## trouble... "five", "one" are not local variables. As you can see, the problem is how can I create local variable one, two ... five to correspond the 5 TkLabels immediately (dynamically)? ( what to replace the ??? ) So, I came out by using eval binding to force automatically create local variables base on it name. Unfortunately, it does not work. So, what's your suggestion? Do not using array ? write them one by one ? or ... variables = %w[one two three four five].map {|e| TkLabel.new(:text=>name, :bg=>'white') {pack(:side=>:top)}} Tk.pack variable[4] :before=>variables[0]