Ruby on Rails Thursday, April 26, 2012

Hello,

I've been wondering how to improve this part of code in terms of code
design:

(I'm especially interested in calling the same function with different
default attributes - a lot of code duplication)

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




Thanks for help

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment