在 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 任务代码中。