rails code club 2 @ taipei
TRANSCRIPT
RAILS CODE CLUB #2
+ Rails Tuesday
+ Rails Bridge 自主練習
+ BOARD GAME
19:20 開始
上期回顧
• 1 - Intention revealing method
• 簡單來說就是註解變成 method
• 2 - Special case objects
• 從源頭解決 nil 要特殊處理的問題
3 - REPLACE METHOD WITH METHOD OBJECT
• 主要⺫⽬目的是關進去 refactoring
• 開⼀一個新的 class,method body 移過去
• 讀 code,下註解,把註解變成 method
• 必須跨 methods 的 local variable 改成 instance variable
• 抽出的 method 請放成 private (關起來)
class OriginMethods def a_fat_method !!!! end end
# $%@ + ($@# / ^%) # && ^ %& * #%%^ # 看不懂的⻤⿁鬼 # and 100 lines...
class OriginMethods def a_fat_method !!!! end end
class NewMethodsdef perform
endend
# $%@ + ($@# / ^%) # && ^ %& * #%%^ # 看不懂的⻤⿁鬼 # and 100 lines...
class OriginMethods def a_fat_method !!!! end end
class NewMethods def perform !!!! end end
# $%@ + ($@# / ^%) # && ^ %& * #%%^ # 看不懂的⻤⿁鬼 # and 100 lines...
class OriginMethods def a_fat_method !!!! end end
class NewMethods def perform !!!! end end
# $%@ + ($@# / ^%) # && ^ %& * #%%^ # 看不懂的⻤⿁鬼 # and 100 lines...
NewMethods.new.perform
class NewMethods !!!! def perform File.open(??????????) # ... end end !class OriginMethods def a_fat_method(file_name) NewMethods.new.perform end end
?
class NewMethods !!!! def perform File.open( ) # ... end end !class OriginMethods def a_fat_method(file_name) NewMethods.new end end
class NewMethods !!!! def perform File.open( ) # ... end end !class OriginMethods def a_fat_method(file_name) NewMethods.new end end
(file_name).perform
class NewMethods !!!! def perform File.open( ) # ... end end !class OriginMethods def a_fat_method(file_name) NewMethods.new end end
def initialize(file_name)@file_name = file_name
end
(file_name).perform
class NewMethods !!!! def perform File.open( ) # ... end end !class OriginMethods def a_fat_method(file_name) NewMethods.new end end
@file_name
def initialize(file_name)@file_name = file_name
end
(file_name).perform
看懂以後 加⼊入註解
看懂以後 加⼊入註解
然後 註解變 method
改成 instance variable