0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Ruby】nil or 未定義の場合の代入演算子

Posted at

メモとして残します。

代入演算子というのかは定かではありませんが、左辺がnil、または存在しない場合のみ、右辺を左辺に代入するという演算子です。

■やり方

hoge = hoge || 'nilの場合代入される'
要するに上記を省略して書くと下記のようになる。

hoge = nil
hoge ||= '代入されるよ'
#>> hoge = '代入されるよ'
hoge = ''
hoge ||= '代入されないよ'
#>> hoge = ''

以上

0
0
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?