字面量 Literals

Crystal提供了一些字面量用于创建某些基本类型的值。

Literal

Sample values

18, -12, 19_i64, 14_u32,64_u8

1.0, 1.0_f32, 1e10, -0.5

"foo\tbar", %("あ"), %q(foo #{foo})

[1, 2, 3], [1, 2, 3] of Int32, %w(one two three)

{"foo" => 2}, {} of String => Int32

MyType{"foo" => "bar"}

/(foo)?bar/, /foo #{foo}/imx, %r(foo/)

{name: "Crystal", year: 2011}, {"this is a key": 1}

->(x : Int32, y : Int32) { x + y }

最后更新于