I encountered the following Ruby code:
class MyClass
attr_accessor :items
...
def each
@items.each{|item| yield item}
end
...
end
A Ruby method that receives a code block invokes it by calling it with the yield
keyword. It can be used to iterate over a list but it is not a iterator like what you find in other some other languages.
Here is a good explanation that explains it better than I would ever be able to.
As cpm said its taking the block and executing it
Simple example:
def my_method
yield
end
my_method do
puts "Testing yield"
end
Testing yield
=> nil