Created
July 27, 2010 01:14
-
-
Save scottswezey/491555 to your computer and use it in GitHub Desktop.
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
# **Updates** | |
%w{body_labor refinish_labor frame_labor}.each do |rate| | |
%w{mean mathematical_mode lowest highest}.each do |method| | |
@result.send(rate).send(method) | |
end | |
end | |
# **Original** | |
%table | |
%tr | |
%th | |
%th Avg. | |
%th Mode | |
%th Min. | |
%th Max. | |
%tr | |
%th Body Labor | |
%td= pretty_number_to_currency @result.body_labor.mean | |
%td= pretty_number_to_currency @result.body_labor.mathematical_mode | |
%td= pretty_number_to_currency @result.body_labor.lowest | |
%td= pretty_number_to_currency @result.body_labor.highest | |
%tr | |
%th Refinish Labor | |
%td= pretty_number_to_currency @result.refinish_labor.mean | |
%td= pretty_number_to_currency @result.refinish_labor.mathematical_mode | |
%td= pretty_number_to_currency @result.refinish_labor.lowest | |
%td= pretty_number_to_currency @result.refinish_labor.highest |
Do something like:
- %w{mean mathematica lowest highest}.each do |method|
= pretty_number_to_currency @result.refinish_labor.send(method) - end
For maximum awesome, make it a helper accepting an Array to keep it DRY .
Can that also be applied to the middle portion?
@result.SOMETHING.send(method)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So I have this table in one of my haml views. The first header row is its own thing, but after that I have maybe 10 more rows that are almost an exact match to the first two content rows. Instead of @result.refinish_labor, its @result.something_else each time... Can someone give me some tips on how to best refactor this?