Ok here is what I want to do:
I pass a block to a method like: Generator.generate(...) {|x| ...}. I want to store the block because I call it in some sub routine that gets called a bunch of times from different places.
Sure I could drag along &block through all methods and calls, but I want to actually save it in a class variable and use it in the appropriate method.
Something like this:
class Generator
class << self
attr_accessor :my_block
def generate(..., &block)
my_block = &block
....each {important_method(x)}
end
def important_method(x)
my_block.yield(x)
end
end
end
Is it possible to store a block and yield it later with some arguments?
You need to make 2 adjustments to your code: