From ddcfcf9a0ae072351aabc735d5f87194400e50a9 Mon Sep 17 00:00:00 2001 From: Hiroshi Kono Date: Sat, 22 May 2010 20:50:05 +0900 Subject: [PATCH] p.140 extract method "discount_factor". --- chapter6/Replace_Temp_with_Query.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/chapter6/Replace_Temp_with_Query.rb b/chapter6/Replace_Temp_with_Query.rb index 65ada58..27323a4 100644 --- a/chapter6/Replace_Temp_with_Query.rb +++ b/chapter6/Replace_Temp_with_Query.rb @@ -7,15 +7,15 @@ def initialize(quantity, price) def price - if base_price >1000 - discount_factor = 0.95 - else - discount_factor = 0.98 - end - base_price * discount_factor + a_discount_factor = discount_factor + base_price * a_discount_factor end def base_price @quantity * @item_price end + + def discount_factor + base_price > 1000 ? 0.95 : 0.98 + end end