rails code club 2 @ taipei

15
RAILS CODE CLUB #2 + Rails Tuesday + Rails Bridge 自主練習 + BOARD GAME 19:20 開始

Upload: bruce-li

Post on 16-Apr-2017

605 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Rails Code Club 2 @ Taipei

RAILS CODE CLUB #2

+ Rails Tuesday

+ Rails Bridge 自主練習

+ BOARD GAME

19:20 開始

Page 2: Rails Code Club 2 @ Taipei

上期回顧

• 1 - Intention revealing method

• 簡單來說就是註解變成 method

• 2 - Special case objects

• 從源頭解決 nil 要特殊處理的問題

Page 3: Rails Code Club 2 @ Taipei

3 - REPLACE METHOD WITH METHOD OBJECT

• 主要⺫⽬目的是關進去 refactoring

• 開⼀一個新的 class,method body 移過去

• 讀 code,下註解,把註解變成 method

• 必須跨 methods 的 local variable 改成 instance variable

• 抽出的 method 請放成 private (關起來)

Page 4: Rails Code Club 2 @ Taipei

class OriginMethods def a_fat_method !!!! end end

# $%@ + ($@# / ^%) # && ^ %& * #%%^ # 看不懂的⻤⿁鬼 # and 100 lines...

Page 5: Rails Code Club 2 @ Taipei

class OriginMethods def a_fat_method !!!! end end

class NewMethodsdef perform

endend

# $%@ + ($@# / ^%) # && ^ %& * #%%^ # 看不懂的⻤⿁鬼 # and 100 lines...

Page 6: Rails Code Club 2 @ Taipei

class OriginMethods def a_fat_method !!!! end end

class NewMethods def perform !!!! end end

# $%@ + ($@# / ^%) # && ^ %& * #%%^ # 看不懂的⻤⿁鬼 # and 100 lines...

Page 7: Rails Code Club 2 @ Taipei

class OriginMethods def a_fat_method !!!! end end

class NewMethods def perform !!!! end end

# $%@ + ($@# / ^%) # && ^ %& * #%%^ # 看不懂的⻤⿁鬼 # and 100 lines...

NewMethods.new.perform

Page 8: Rails Code Club 2 @ Taipei

class NewMethods !!!! def perform File.open(??????????) # ... end end !class OriginMethods def a_fat_method(file_name) NewMethods.new.perform end end

?

Page 9: Rails Code Club 2 @ Taipei

class NewMethods !!!! def perform File.open( ) # ... end end !class OriginMethods def a_fat_method(file_name) NewMethods.new end end

Page 10: Rails Code Club 2 @ Taipei

class NewMethods !!!! def perform File.open( ) # ... end end !class OriginMethods def a_fat_method(file_name) NewMethods.new end end

(file_name).perform

Page 11: Rails Code Club 2 @ Taipei

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

Page 12: Rails Code Club 2 @ Taipei

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

Page 13: Rails Code Club 2 @ Taipei
Page 14: Rails Code Club 2 @ Taipei

看懂以後 加⼊入註解

看懂以後 加⼊入註解

然後 註解變 method

Page 15: Rails Code Club 2 @ Taipei

改成 instance variable