Ruby中是否有更好的方法可以使用可枚举的每个参数调用self方法?会减少以下代码的东西:
class Cook
def cook_dinner(*recipes)
recipes.each { |recipe| cook recipe }
end
def cook(recipe)
do_something_with recipe
end
end
这样的事情?
class Cook
def cook_dinner(*recipes)
recipes.apply_to_each(:cook)
end
def cook(recipe)
do_something_with recipe
end
end