Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Rails Code Club 2 @ Taipei

619 views

Published on

Published in: Technology
  • Be the first to comment

Rails Code Club 2 @ Taipei

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

×