The block is passed in the same way as the argument to this function. This can be specified explicitly, for example:
class Test
def my_each(&block)
"abcdeabcabc".scan("a") do |x|
puts "!!! block"
yield x
end
end
end
, (puts, ), , . , yield, LocalJumpError ( , , Rubinius). , "!!!".
. , , , , if block, yield s. content_tag Rails. -. :
content_tag :div do
content_tag :div
end
... , :
<div>
<div></div>
</div>
, "" ( ) . , yield - . , .
UPD:
Enumerator, each es, , , .
: my_each:
class Test
def my_each(&block)
if block
"abcdeabcabc".scan("a") { |x| yield x }
else
Enumerator.new(self, :my_each)
end
end
end