我刚刚开始Ruby并学习模块的概念。我明白模块的一个用途是更好地组织代码并避免名称冲突。比方说,我有一堆这样的模块(我还没有列入执行情况这并不重要) :Ruby模块和类
module Dropbox
class Base
def initialize(a_user)
end
end
class Event < Base
def newFile?
end
def newImage?
end
end
class Action < Base
def saveFile(params)
end
end
end
和另一个模块:
module CustomURL
class Base
def initialize(a_user, a_url, a_method, some_args, a_regex)
end
end
class Event < Base
def initialize(a_user, a_url, a_method, some_args, a_regex)
end
def change?
end
end
class Action < Base
def send_request(params)
end
end
end
我将有一堆这些模块(10+,用于Gmail,Hotmail等)。我试图弄清楚的是,这是组织我的代码的正确方法吗?
基本上,我使用的模块来表示“服务”,所有服务都将有一个共同的接口类(基地初始化,行动的操作列表和事件监控)。
我建议将其移至codereview.stackexchange.com。你的代码起作用了,它并不像它可能的那样严密。 – 2012-01-29 16:57:29