Spec-Zone.ru › Crystal

Литералы

Crystal предоставляет несколько литералов для создания значений некоторых базовых типов.

Литерал Примеры значений
Nil nil
Bool true, false
Целые числа 18, -12, 19_i64, 14_u32,64_u8
Числа с плавающей точкой 1.0, 1.0_f32, 1e10, -0.5
Char 'a', '\n', 'あ'
String "foo\tbar", %("あ"), %q(foo #{foo})
Symbol :symbol, :"foo bar"
Array [1, 2, 3], [1, 2, 3] of Int32, %w(one two three)
Подобный массиву Set{1, 2, 3}
Hash {"foo" => 2}, {} of String => Int32
Подобный хешу MyType{"foo" => "bar"}
Range 1..9, 1...10, 0..var
Regex /(foo)?bar/, /foo #{foo}/imx, %r(foo/)
Tuple {1, "hello", 'x'}
NamedTuple {name: "Crystal", year: 2011}, {"this is a key": 1}
Proc ->(x : Int32, y : Int32) { x + y }
Command `echo foo`, %x(echo foo)

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/reference/1.2/syntax_and_semantics/literals/index.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API