阅读背景:

Ruby:通过模块添加东西以初始化方法

来源:互联网 

In Ruby I want to have a class include a series of modules and have these individual modules execute a block or method (or just find some way to edit an instance variable) when initializing that class. I know I can do this by creating a method in the module and then calling it in the class' initialize method, but I want some way to do this by simply including the module and calling one method to execute any code the modules add to initialize, that way I can have a large amount of things included in a class without worrying about adding a line of code in the initialize method for every single module included. I've checked out aliasing, super, and related things but haven't gotten anything... If it helps to understand what I'm hoping to accomplish here's some pseudocode:In Ruby I want to have a class include a series




你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: