Created
September 25, 2011 16:16
-
-
Save danbernier/1240775 to your computer and use it in GitHub Desktop.
One way I could DRY up hunt_for_bugs and fix_bugs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def hunt_for_bugs(score, location) | |
bug_work(hidden_bugs(location), :hide_points).size | |
end | |
def fix_bugs(score, location) | |
just_fixed = bug_work(found_bugs(location), :hit_points) | |
@bug_list.reject! { |bug| bug.dead? } | |
just_fixed.size | |
end | |
def bug_work(bugs, :attr) | |
bugs.take_while do |bug| | |
points = [bug.send(attr), score].min | |
bug.send("#{attr}=".to_sym, bug.send(attr) - points) | |
score -= points | |
bug.send(attr) == 0 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment