Easy question

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

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.

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

Alan F. 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

Alan F. 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.

Alan
sorry