字面量 Literals
最后更新于
最后更新于
Crystal提供了一些字面量用于创建某些基本类型的值。
Literal
Sample values
nil
true
, false
18
, -12
, 19_i64
, 14_u32
,64_u8
1.0
, 1.0_f32
, 1e10
, -0.5
'a'
, '\n'
, 'あ'
"foo\tbar"
, %("あ")
, %q(foo #{foo})
:symbol
, :"foo bar"
[1, 2, 3]
, [1, 2, 3] of Int32
, %w(one two three)
Set{1, 2, 3}
{"foo" => 2}
, {} of String => Int32
MyType{"foo" => "bar"}
1..9
, 1...10
, 0..var
/(foo)?bar/
, /foo #{foo}/imx
, %r(foo/)
{1, "hello", 'x'}
{name: "Crystal", year: 2011}
, {"this is a key": 1}
->(x : Int32, y : Int32) { x + y }
`echo foo`
, %x(echo foo)