diff --git a/src/number.cr b/src/number.cr index 62177e78d89c..9aae19e1eb8a 100644 --- a/src/number.cr +++ b/src/number.cr @@ -71,6 +71,13 @@ struct Number # ints = Int64[1, 2, 3] # ints.class # => Array(Int64) # ``` + # + # This is similar to an array literal of the same item type: + # + # ``` + # Int64[1, 2, 3, 4] # : Array(Int64) + # [1, 2, 3, 4] of Int64 # : Array(Int64) + # ``` macro [](*nums) Array({{@type}}).build({{nums.size}}) do |%buffer| {% for num, i in nums %} @@ -92,6 +99,14 @@ struct Number # ints = Int64.slice(1, 2, 3) # ints.class # => Slice(Int64) # ``` + # + # This is a convenient alternative to `Slice.[]` for designating a + # specific item type which also considers autocasting. + # + # ``` + # Int64.slice(1, 2, 3, 4) # : Slice(Int64) + # Slice[1_i64, 2_i64, 3_i64, 4_i64] # : Slice(Int64) + # ``` macro slice(*nums, read_only = false) %slice = Slice({{@type}}).new({{nums.size}}, read_only: {{read_only}}) {% for num, i in nums %} @@ -110,6 +125,14 @@ struct Number # ints = Int64.static_array(1, 2, 3) # ints.class # => StaticArray(Int64, 3) # ``` + # + # This is a convenvenient alternative to `StaticArray.[]` for designating a + # specific item type which also considers autocasting. + # + # ``` + # Int64.static_array(1, 2, 3, 4) # : StaticArray(Int64) + # StaticArray[1_i64, 2_i64, 3_i64, 4_i64] # : StaticArray(Int64) + # ``` macro static_array(*nums) %array = uninitialized StaticArray({{@type}}, {{nums.size}}) {% for num, i in nums %} diff --git a/src/slice.cr b/src/slice.cr index ebdd7c5f4cc8..4a49f77b97e6 100644 --- a/src/slice.cr +++ b/src/slice.cr @@ -29,7 +29,8 @@ struct Slice(T) # If `T` is a `Number` then this is equivalent to # `Number.slice` (numbers will be coerced to the type `T`) # - # See also: `Number.slice`. + # * `Number.slice` is a convenient alternative for designating a + # specific numerical item type. macro [](*args, read_only = false) # TODO: there should be a better way to check this, probably # asking if @type was instantiated or if T is defined diff --git a/src/static_array.cr b/src/static_array.cr index 714e3368a187..ee502fb63035 100644 --- a/src/static_array.cr +++ b/src/static_array.cr @@ -47,7 +47,8 @@ struct StaticArray(T, N) # ary.class # => StaticArray(Char | Int32, 2) # ``` # - # See also: `Number.static_array`. + # * `Number.static_array` is a convenient alternative for designating a + # specific numerical item type. macro [](*args) %array = uninitialized StaticArray(typeof({{*args}}), {{args.size}}) {% for arg, i in args %}