LoginSignup
5
5

More than 5 years have passed since last update.

Rubyでは文字列でもできるだけ'(シングルクオーテーション)を使おう

Posted at

Rubyに限らないのだけれど、

p "#{1+1}"
=> "2"
p '#{1+1}'
=> "\#{1+1}"

"(ダブルクオーテーション)では式が評価されたりする。これが意図しないバグを含むかもしれないからできるだけ'(シングルクオーテーション)を使おうということ。文字列を表すのに"(ダブルクオーテーション)を使う言語と同時に使っていると、ついつい"(ダブルクオーテーション)を使ってしまうがそれはダメ。

と自分に戒める。反省。

5
5
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
5
5