LoginSignup
0
0

More than 1 year has passed since last update.

美しきRubyリファクタリング(Part1)

Posted at

イントロダクション

Part1で終わるかもしれませんが、シリーズ化決定。

その名も「美しきRubyリファクタリング」。
名前が映画みたいでカッコいいね。

今日のリファクタリング

RSpecを書いているときに出くわしたリファクタリングのチャンス。

before:

let(:process) do
  if process_type.is_a? Array
    process_type
  else
    [process_type]
  end
end

after:

let(:process) { process_type.is_a?(Array) ? process_type : [process_type] }

これでとても簡潔なコードになった!

最後に

三項演算子が好きではない方にはグッと来ないリファクタリングだったかもしれないことに少し反省。
だが、私は「1行で書けるところは1行で書く」ということを愛している(茶番)


機会があれば、次の「美しきRubyリファクタリング(Part2)」でお会いしましょう〜( ´ v ` )

それでは〜( ´ v ` )

0
0
2

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