<div>You're asking for no length with [3,0] hence it slicing at position 3 for 0 chars. With the second version you're using an out of range start position hence the nil.<div><br></div><div>N</div></div>
<div><br>Neil<br></div>
<p style="color: #A0A0A8;">On Wednesday, 7 September 2011 at 09:29, Michael Pavling wrote:</p>
<blockquote type="cite" style="border-left-style:solid;border-width:1px;margin-left:0px;padding-left:10px;">
<span><div><div>I'm just running through the Ruby Koans for a bit of fun, and I've<br>quickly come upon a case that doesn't make sense to me. I've re-read<br>the documentation, but I still don't understand why it happens.<br><br>Having a play with this array in the console:<br> >> x = %w(a b c)<br> => ["a", "b", "c"]<br> >> x[1]<br> => "b"<br> >> x[2]<br> => "c"<br> >> x[3]<br> => nil<br><br>All makes sense so far, but when I call x[3,0] I *expect* it to return<br>nil (as the starting index is out of range), but it returns an empty<br>array:<br> >> x[3,0]<br> => []<br><br>x[4,0] behaves as I expected:<br> >> x[4,0]<br> => nil<br><br>I know it's going to be me not understanding the documentation<br>properly, but *unless* I can understand it, it's going to leave me<br>confused. Can anyone explain it simply and clearly, please?<br><br>TIA<br>_______________________________________________<br>Chat mailing list<br><a href="mailto:Chat@lists.lrug.org">Chat@lists.lrug.org</a><br><a href="http://lists.lrug.org/listinfo.cgi/chat-lrug.org">http://lists.lrug.org/listinfo.cgi/chat-lrug.org</a><br></div></div></span>
</blockquote>
<div>
<br>
</div>