Assign nil to array element : nil « Language Basics « Ruby






Assign nil to array element


  a = [ 1, 'cat', 3.14 ]   # array with three elements

  a[0]
  # set the third element
  a[2] = nil
  # dump out the array
  p a

 








Related examples in the same category

1.Compact an array: it removes the nils
2.Is it a nil value
3.If x is non-nil
4.see if it is nil: