Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Tama Ruby Kaigi 01

Tama Ruby Kaigi 01

Avatar for Yuki Kondo

Yuki Kondo

July 04, 2019
Tweet

More Decks by Yuki Kondo

Other Decks in Technology

Transcript

  1. Yuki Kondo(@konchan_x)
 
 # 所属 
 DeNA ヘルスケア
 
 #

    やってること 
 サーバーサイドエンジニア
 Ruby, Rails
 Go, GAE, Firestore
 Vue.js, Nuxt.js, Flutter
 
 # 前職
 SIer, SE, Dive into Code

  2. 見てもらうために読みやすいコードを意識する
 02
 # 命名規則
 ユーザーのメールアドレスを取得したい
 NG: user.get_email
 OK: user.email
 


    # メソッド定義のシグネチャ
 ユーザーIDに該当するユーザーを取得したい
 NG: def find_by_id(user)
 OK: def find_by_id(user_id)

  3. プロの技を盗める
 01
 ・責務分割
 ・delegate(移譲)
 ・||= (自己代入)
 ・DI(依存性注入)
 ・開発Contextごとの実装の違い
 class User


    attr_reader :id
 delegate :name, to: :profile
 
 def initialize(id)
 @id = id
 end
 
 private
 
 def profile
 @profile ||= ::Profile.new(self)
 end
 end
 
 class Profile
 def initialize(user)
 @user = user
 end
 
 def name
 "#{@user.id}: konchan"
 end
 end