From: 7stud -- Date: 2009-02-11T20:05:42+09:00 Subject: Re: simple class question Tom Cloyd wrote: > I can see you were as > surprised (more or less) as I was by the failure of the "return n" > statement to do anything. > I'm a ruby beginner too. > > I will study your example. I'm sure it will teach me a few things. > Thanks! > Here is a little fancier get_data method: def get_data while data = @file.gets yield data.chomp.split end @file.close end A yield statement will send the specified value to a block that you specify to the right of the method call: dp = MyDataProcessor.new("data.txt") dp.get_data {|processed_data| p processed_data} If you need to execute more than one line of code in that block, then you would write it like this: dp.get_data do |processed_data| #some code here #other code here p processed_data end -- Posted via http://www.ruby-forum.com/.