I work on internal Ruby DSL and make it as beautiful as possible. I need the monkey to pay the Symbol class and add some operators. I want to be responsible for how I do this, and I would like to limit the scope and lifetime of the patches to a specific block of code. Is there a standard template for this? Here is some kind of pseudo code to show what I think:
class SomeContext
def self.monkey_patch_region(&block)
context = SomeContext.new
context.monkey_patch_Symbol
context.instance_eval(&block)
context.unmonkey_patch_Symbol
end
def monkey_patch_Symbol
end
def unmonkey_patch_Symbol
end
end
source
share