Created
November 13, 2013 16:50
-
-
Save jgarber/7452338 to your computer and use it in GitHub Desktop.
One of my students just asked about the behavior below and I didn't have a good answer. Do you have an explanation?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2.0.0p247 :001 > a = [1, 2] | |
=> [1, 2] | |
2.0.0p247 :002 > a[1] | |
=> 2 | |
2.0.0p247 :003 > a[2] | |
=> nil | |
2.0.0p247 :004 > a[1,1] | |
=> [2] | |
2.0.0p247 :005 > a[2,1] | |
=> [] ## <- Why is this not nil? | |
2.0.0p247 :006 > a[3,1] | |
=> nil |
Yes, but that's all it says. Did you see an explanation?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://ruby-doc.org/core-2.0/Array.html#method-i-5B-5D
it says it's special case