Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
シンボルの意味について簡単な質問があります (と思います)。ruby の ||= の意味は何ですか? 私は言うコードスニペットを持っています:
...||= [nil]
||= [nil]
「<<」ですか?通常の方法?
x ||= y
と(ほぼ)同じことを意味する
x = x || y
(ただし、評価はx1 回だけです。)
x
主に、変数が偽 (nilまたはfalse) かどうかをチェックし、そうであればデフォルト値に設定するために使用されます。
nil
false