From: Corey Konrad <0011@...> Date: 2007-03-17T07:58:15+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. what i am basically trying to understand is: When i do printer("ball") i am putting the string ball in the arg variable of the printer method. When i call the printer method with the block afterwards what happened to my string i stored in arg? Was it destroyed or when i called the printer method for the second time did ruby create a whole new arg variable with nothing in it and thats why the way i did it didnt work? Do you know what i mean i am trying to understand why what i did didnt work. -- Posted via http://www.ruby-forum.com/.