0
0

More than 1 year has passed since last update.

【Rails】each文を一文で簡潔に書く方法

Posted at

はじめに

リーダブルコードやリファクタリングについて日々勉強をしています。
each文の簡潔な書き方に出会ったので、残しておきます。

やったこと

いつもであれば、こう記述していました。

temps = [1,2,3,4,5,6,7]
temps.each do |temp|
  p(puts) temp #実行する処理
end

これを書き換えると、

temps.each {|temp| p(puts) temp } 

終わりに

一文で書ける為、コードがスッキリします。

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