在Ruby中必须有一种更有效的方法。我有一个方法列表,可以根据每个商店中的代码以不同的方式在多个网站上划分相同的东西(标题,价格)。例如:无效Ruby方法命名:作为参数传递命名空间作为调用方法的一种方式
def store1_get_title
def store1_get_price
def store2_get_title
def store2_get_price
def store3_get_title
def store3_get_price
当调用所有这些功能,我只是想有一个通用的电话说“命名空间”参数来完成调用任何的这些方法,而不必键入了所有的人,是这样的:
for get_all_stores().each do |store|
store::get_title
store::get_price
end
...就像我想这将调用store1_get_title,store1_get_price,store2_get_title,store2_get_price。有没有这样的事情或更好的方式来做到这一点?
希望是有道理的。感谢您的任何意见!
编辑:这些任务在rake任务代码中。