在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任務代碼中。