Easy question


#1

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


#2

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


#3

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


#4

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