From: Corey Konrad <0011@...> Date: 2007-03-17T07:47:41+09:00 Subject: Re: yield Chad Perrin wrote: > On Sat, Mar 17, 2007 at 07:36:21AM +0900, Corey Konrad wrote: >> >> why is that, cant yield be used with arguments? >> >> oh ok, my understanding for some reason was that the method was going to >> remmeber that i set arg to "ball" so that when i used printer with the >> block that "ball" would still be in arg. So is that why it isnt working, >> is because when i call the printer method the second time the value >> stored in arg is destroyed? > > I'm just guessing here, but . . . > > It looks like you're expecting something akin to class behavior from a > method. Perhaps what you want to do is something more like this: > > class Printer > def initialize(arg) > @arg = arg > end > > def iterator_thingie > yield @arg > end > end > > printer = Printer.new("ball") > printer.iterator_thingie {|word| puts word} > > > Then again, maybe that's not the kind of behavior you want. its not that i am looking to get any specific result its that i am trying to understand what is going on behind the scenes so that i can understand why what i did, did not work not just that it in fact did not work. -- Posted via http://www.ruby-forum.com/.