I want disable the rm\_rf method of the FileUtils module in Ruby scripts.
When foo.rb contains:
FileUtils.rm_rf(file)
It should not be run by:
Daemons.run("foo.rb", some_options)
and should give an error message instead.
Does Daemons can do this? Or can some other libraries can do this simply and effectively?
Here's a rough outline of what you want to do.
Using
alias_methodis likely not a good idea unless you define the old method to something else; here methods are defined away. The danger of this approach is that internal behavior may be affected in anticipated ways, e.g., an allowed method uses a disallowed method internally.The following is for singleton (class) methods, the same logic may be used for instance methods. There are several ways this could be implemented, this is just one, meant as a guide.
There's also Module::undef_method and Module::remove_method, which may or may not provide the behavior you want (not sure what you need it to do).