Skip to content

Instantly share code, notes, and snippets.

@danbernier
Created September 25, 2011 16:16
Show Gist options
  • Save danbernier/1240775 to your computer and use it in GitHub Desktop.
Save danbernier/1240775 to your computer and use it in GitHub Desktop.
One way I could DRY up hunt_for_bugs and fix_bugs
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