Ruby: Extending Net::IMAP to include additional commands?
Is it possible to extend a base class to include additional commands? For example, lets say I have a custom IMAP server that supports a command called "WUNTEE"... I would like to use the private Net::IMAP::send_command 开发者_运维问答method to send "WUNTEE", but since its private, how would that be possible? Is that even possible? Thanks.
You can either subclass it as required, which is perfectly acceptable, or patch the base class with the new methods you want. From a design standpoint, a subclass is a cleaner approach, but you may find that some of the other related classes use Net::IMAP directly and getting them to use your specific version is tricky or impractical.
It's actually pretty straight-forward to patch out any methods you don't like with your own implementation by simply re-defining them at any point in the execution of your program.
精彩评论