Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
p.155-156 replace "gamma" method with "compute" method in "Gamma" class.
  • Loading branch information
kono committed May 30, 2010
1 parent 27dbdc1 commit c5c89d2
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions chapter6/Replace_Method_with_Method_Object.rb
@@ -1,16 +1,39 @@
class Account
def gamma(input_val, quantity, year_to_date)
important_value1 = (input_val * quantity + delta)
important_value2 = (input_val * year_to_date) + 100
if (year_to_date - important_value1) > 100
important_value2 -= 20
end
important_value3 = important_value2 * 7
#等々
important_value3 - 2 * important_value1
Gamma.new(self, input_val, quantity, year_to_date).compute
end

def delta
return 100
end
end

class Gamma
attr_reader :account,
:imput_val,
:quantity,
:year_to_date,
:important_value1,
:important_value2,
:important_value3

def initialize(account, input_val_arg, quantity_arg, year_to_date_arg)
@account = account
@input_val = input_val_arg
@quantity = quantity_arg
@year_to_date = year_to_date_arg
end

def compute
@important_value1 = (@input_val * @quantity) + @account.delta
@important_value2 = (@input_val * @year_to_date) + 100
if (year_to_date - important_value1) > 100
@important_value2 -= 20
end
@important_value3 = @important_value2 * 7
# and so on.
@important_value3 - 2 * @important_value1
end

end

0 comments on commit c5c89d2

Please sign in to comment.