As a suffix

As a suffix

An if can be written as an expression’s suffix:

a = 2 if some_condition

# The above is the same as:
if some_condition
  a = 2
end

This sometimes leads to code that is more natural to read.

To the extent possible under law, the persons who contributed to this workhave waived
all copyright and related or neighboring rights to this workby associating CC0 with it.
https://crystal-lang.org/docs/syntax_and_semantics/as_a_suffix.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部