I have a block which I need to pass to File.open and another method XXobject#read. Since I passed the same block to those two methods, I would like to find a way to avoid duplicating the code of block.
I tried to define a Proc object, but File.open seems not to accept a Proc object. I am wondering why. As far as I know, a block is stored as a Proc object.
Is there a way to avoid duplicated blocks in Ruby?
You need to convert Proc to Block: