Why Treat 0 as True in Ruby?

前端 未结 3 958
庸人自扰
庸人自扰 2020-12-30 19:45

I\'m reading through the excellent Ruby on Rails Tutorial and have encountered the following code.

if 0
  true
else
  false
end

The above r

3条回答
  •  我在风中等你
    2020-12-30 20:02

    In ruby, if exists, it's true. If not, it's false.

    so, with Ruby null(no address assigned) and false are only false.

    All others are true because it has address assigned to it.

    I think of this way; "Does it exist?"

提交回复
热议问题