LoginSignup
0
0

More than 3 years have passed since last update.

if railsリファクター

Last updated at Posted at 2020-04-27

ifにまつわるリファクター

もうちょっといい感じになるでしょ・・・!でも書き方がわからないなんてときのTips

条件と代入したいものが同じ!

rate = if point
  point
else
  20
end

rate = point_usable_limit_rate || 20

ifが二重ネストしているが、最初のifの結果と中のifが同じ場合

if CCCC
  if DDDD
    AAAA
  else
    BBBB
  end
    BBBB
end

unless CCCC? # 最初にCCCC以外を弾く
    if DDDD
       AAAAA
    end
    BBBB
end

同じカラムを見に行くが値が違う時

if AAA.type == "MAYO" || AAA.type == "BUTTER"
  "MAYOBUTTER"
end

if AAA.type.in?(["MAYO", "BUTTER"])
  "MAYOBUTTER"
end
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0