我一直想知道如何在代码设计方面改进这部分代码:
(我对使用不同的默认属性调用相同的函数特别感兴趣——大量的代码重复)
def follow_pages(number_of_pages = 5, sleep_interval = 5)
process_pages true, number_of_pages, sleep_interval
end
def unfollow_pages(number_of_pages = 5, sleep_interval = 5)
process_pages false, number_of_pages, sleep_interval
end
def process_pages(follow = true, number_of_pages = 5, sleep_interval = 5)
number_of_pages.times do |page|
sleep rand(sleep_interval)
if follow
follow_all_pages
else
unfollow_all_pages
end
end
end