-
Book Overview & Buying
-
Table Of Contents
Polished Ruby Programming - Second Edition
By :
When we added support for configuring the plugin system, we passed arguments from the plugin method to the before_load and after_load methods:
class Libry
def self.plugin(mod, ...)
# plugin loading code
mod.before_load(self, ...) if mod.respond_to?(:before_load)
# include/extend code
mod.after_load(self, ...) if mod.respond_to?(:after_load)
end
end
If either the before_load or after_load methods are supported by the plugin, this is fine. However, what if the plugin does not support those methods? What happens then is that users can provide any arguments to the plugin method, and the plugin method will just ignore them. That's bad for two reasons. First, the user probably passed arguments expecting them to do something, and they don't know the arguments are being ignored. Second, it means that if the plugin adds a before_load or after_load method in the future, the user's code could break.
One way to handle this is to have...
Change the font size
Change margin width
Change background colour