easy question, but can anyone give me a referance to what ''yield'' is? how to implement, where to use? ..feeling kinda stupid, but thanks in advance, j -- Posted via http://www.ruby-forum.com/.
jack wrote:> easy question, but can anyone give me a referance to what ''yield'' is? > how to implement, where to use? ..feeling kinda stupid, but thanks in > advance, > > jyield inside a method passes control to a supplied block. so for example, the implementation of Array#each might look something like: def each(&block) for i in 0...size yield self[i] end end so you can do a.each {|thing| puts thing.to_s} yield is ''calling'' the block ( {|thing| puts thing.to_s} ) with each item in turn. Does this make sense ? Alan -- Posted via http://www.ruby-forum.com/.
Alan Francis wrote:> jack wrote: >> easy question, but can anyone give me a referance to what ''yield'' is? >> how to implement, where to use? ..feeling kinda stupid, but thanks in >> advance, >> >> j >Some useful stuff here: http://www.rubycentral.com/book/tut_containers.html -- Posted via http://www.ruby-forum.com/.
Alan Francis wrote:> jack wrote: >> easy question, but can anyone give me a referance to what ''yield'' is? >> how to implement, where to use? ..feeling kinda stupid, but thanks in >> advance, >> >> j > > yield inside a method passes control to a supplied block. > >> Alansorry -- Posted via http://www.ruby-forum.com/.