Forum: Ruby Accessing array by slicing

21cb9b23398a37fc04850a17c2a6ba5d?d=identicon&s=25 Roy Browne (rubymore)
on 2017-03-20 14:09

array = [A,B,C,D]

array[1]  => B
array[3] => D

array[1,2] => [B,C]
array[0,3] => [A,B,C]

Why does array[4,0] return [], yet array[5,0] returns nil?

Both should be out of bounds.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.