email55555 email55555 wrote: > 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 > > [...] > 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] Yes, I'd use an Array like in your sample. Tk is a bit more chaotic in this matter which is probably why they are using variables instead. You could also use a Hash like this: labels = Hash.new %w[one two three four five].each do |name| label = TkLabel.new(:text => name, :bg => 'white') do pack(:side=>:top) end labels[name] = label end Tk.pack(label["four"], :before => label["one"])