SlideShare a Scribd company logo
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 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...
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
Rails Code Club 2 @ Taipei
看懂以後	

加⼊入註解
看懂以後	

加⼊入註解
然後	

註解變	

method
改成	

instance variable

More Related Content

PDF
Metaprogramming in Ruby
PDF
Reactive Web Applications with Scala & Liftweb - CodeWeek 2015
ODP
06. haskell type builder
PDF
07. haskell Membership
PPTX
JavaScript Common Mistake
PDF
From android/java to swift (3)
PDF
javascript objects
PDF
Demystifying Shapeless
Metaprogramming in Ruby
Reactive Web Applications with Scala & Liftweb - CodeWeek 2015
06. haskell type builder
07. haskell Membership
JavaScript Common Mistake
From android/java to swift (3)
javascript objects
Demystifying Shapeless

What's hot (15)

PPT
JavaScript Data Types
PDF
JavaScript - Chapter 4 - Types and Statements
PDF
Software Developer Training
PPTX
Chapter2 array of objects
PDF
Crystal: tipos, peculiaridades y desafios
PDF
05 ruby classes
PPT
Intermediate JavaScript
PDF
What can scala puzzlers teach us
ODP
What I Love About Ruby
PPTX
Scala syntax analysis
PPT
البرمجة الهدفية بلغة جافا - مصفوفة الكائنات
PPTX
Javascript basics
PDF
JavaScript For CSharp Developer
PDF
Programming in scala - 1
PDF
Scala fun part: Reflection(runtime)
JavaScript Data Types
JavaScript - Chapter 4 - Types and Statements
Software Developer Training
Chapter2 array of objects
Crystal: tipos, peculiaridades y desafios
05 ruby classes
Intermediate JavaScript
What can scala puzzlers teach us
What I Love About Ruby
Scala syntax analysis
البرمجة الهدفية بلغة جافا - مصفوفة الكائنات
Javascript basics
JavaScript For CSharp Developer
Programming in scala - 1
Scala fun part: Reflection(runtime)
Ad

Viewers also liked (6)

PDF
Refactoring Workshop (Rails Pacific 2014)
PDF
Rx tech ltr of agreement #32
PDF
011 優化時間分配的 app 跟心得
PDF
003 Ruby小觀念與小技巧Part2
PPSX
Gosari osasungarriak
PDF
007 Facebook Open Graph 相關開發簡單介紹 公開版
Refactoring Workshop (Rails Pacific 2014)
Rx tech ltr of agreement #32
011 優化時間分配的 app 跟心得
003 Ruby小觀念與小技巧Part2
Gosari osasungarriak
007 Facebook Open Graph 相關開發簡單介紹 公開版
Ad

More from Bruce Li (11)

PDF
RSpec best practice - avoid using before and let
PDF
Unlock dependency between client teams and API team with API mock and proxy
PDF
Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)
PDF
Rails Code Club 3 @ Taipei
PDF
010 Better and Better 工程師就業兩年多的心得雜談
PDF
009 增進效率的雜七雜八mac快速鍵與設定 part 2
PDF
008 vim超基礎入門
PDF
006 實作小玩具功能:chrome desktop notification
PDF
004 動機 單純的力量 讀書心得
PDF
002 增進效率的有的沒的快速鍵與設定
PDF
001 Ruby小觀念與小技巧
RSpec best practice - avoid using before and let
Unlock dependency between client teams and API team with API mock and proxy
Make your Rails console AWESOME (Ruby SG meetup 2016-03-29)
Rails Code Club 3 @ Taipei
010 Better and Better 工程師就業兩年多的心得雜談
009 增進效率的雜七雜八mac快速鍵與設定 part 2
008 vim超基礎入門
006 實作小玩具功能:chrome desktop notification
004 動機 單純的力量 讀書心得
002 增進效率的有的沒的快速鍵與設定
001 Ruby小觀念與小技巧

Recently uploaded (20)

PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Cloud computing and distributed systems.
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Big Data Technologies - Introduction.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Spectroscopy.pptx food analysis technology
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Encapsulation theory and applications.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
KodekX | Application Modernization Development
Unlocking AI with Model Context Protocol (MCP)
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Cloud computing and distributed systems.
The Rise and Fall of 3GPP – Time for a Sabbatical?
Big Data Technologies - Introduction.pptx
MIND Revenue Release Quarter 2 2025 Press Release
sap open course for s4hana steps from ECC to s4
Spectroscopy.pptx food analysis technology
NewMind AI Weekly Chronicles - August'25 Week I
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
cuic standard and advanced reporting.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Spectral efficient network and resource selection model in 5G networks
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Encapsulation theory and applications.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
KodekX | Application Modernization Development

Rails Code Club 2 @ Taipei