Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Create Array with nil

  • 0_i64
n = 5
nums = (0_i64.as(Int64 | Nil)..n).to_a
puts typeof(nums) # Array(Int64 | Nil)

other = [nil] + (1..n).to_a
puts typeof(other) # Array(Int32 | Nil)