From: Marnen Laibow-Koser Date: 2009-11-19T04:52:36+09:00 Subject: Re: Ruby/tk Help Please Sean Ob wrote: [...] > i have read a lot of things pertaining to blocks, but i still don't > understand them. Then keep reading and practicing. There is no shortcut. > > for example i have tried several variations of > > result*@list2.each + '\n' > #i realize this is horrible syntax, but what i want to do is take result > and then print the result*each element of list2 on separate lines It's incorrect syntax. Think of it this way: In English, you're saying "I want to do something with each element of @list2." In Ruby, that's @list2.each do |element| something end The each method takes each element in turn and calls the block with that element. Now, what's the "something" you want to do with each element? You want to multiply each element by result, convert the result to a string, and append \n. In Ruby, that's (element * result).to_s + "\n" Putting those constructs together, we get @list2.each do |element| (element * result).to_s + "\n" end Does that make more sense? In fact, I probably wouldn't write it like this. I'd probably do @list2.collect {|e| e * result}.join "\n" The output is slightly different, but it's probably what you want. Determining why this works (and the difference in output) is left as an exercise to the student. :) [...] > i realize my method of just jumping into a language trying to do complex > things right away is not a very logical approach however i learn best by > doing and by example. So do I. Just make sure you learn your prerequisites. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen@marnen.org -- Posted via http://www.ruby-forum.com/.