The answer highly depends on how some code is stored in Lib.rb. I assume that it is not free standing code like in a script, but rather contained in a Proc, function or (class/module) method. What you can do then is just change the some code in your original block to a call to the respective object like this: