Skip to content

Instantly share code, notes, and snippets.

@myronmarston
Forked from Fluxx/dry.rb
Created August 18, 2011 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myronmarston/1155222 to your computer and use it in GitHub Desktop.
Save myronmarston/1155222 to your computer and use it in GitHub Desktop.
day = case self.type
when 'fast' then :fast_completion_day
when 'super_fast' then :super_fast_completion_day
when 'ludicrous' then :ludicrous_completion_day
else :budget_completion_day
end
self.value = Increment.first.max_hours * Incrementor.first.send(day)
@myronmarston
Copy link
Author

prefix = %w[ fast super_fast ludicrous ].include?(self.type) ? self.type : "budget"
self.value = Increment.first.max_hours * Incrementor.first.send(:"#{prefix}_completion_day")

This is probably about as short and dry as you can get it. That said, I'm not sure that this is more clear/easy to read. I'd probably add a method to Incrementor like Incrementor#completion_day_for(type) that would take care of this logic for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment