什么是||= 红宝石? [英] what is ||= in ruby?
本文介绍了什么是||= 红宝石?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能的重复:
在 Ruby 中 ||= 是什么意思?
什么是 ruby 中的 ||=?
what is ||= in ruby?
推荐答案
这是一个条件分配.如果变量是 nil
或 false
它将被右侧的值替换;如果它已经有一个不是 nil
或 false
的值,它会保留那个值.
It's a conditional assignment. If the variable is nil
or false
it will be replaced with the value on the right hand side; if it already has a value other than nil
or false
it will keep that value.
这篇关于什么是||= 红宝石?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文