什么是||= 红宝石? [英] what is ||= in ruby?

查看:48
本文介绍了什么是||= 红宝石?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
在 Ruby 中 ||= 是什么意思?

什么是 ruby​​ 中的 ||=?

what is ||= in ruby?

推荐答案

这是一个条件分配.如果变量是 nilfalse 它将被右侧的值替换;如果它已经有一个不是 nilfalse 的值,它会保留那个值.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆