From: Colin Bartlett Date: 2011-09-11T09:56:04+09:00 Subject: Re: Unexpected behavior of Ruby array On Thu, Sep 8, 2011 at 2:00 PM, Gavin Kistner wrote: > On Sep 8, 2011, at 2:08 AM, Adam Prescott wrote: >> There's discussion about this at http://www.ruby-forum.com/topic/1393096 >> Oh, and http://redmine.ruby-lang.org/issues/4541 > > Also discussed here: > http://stackoverflow.com/questions/3568222/array-slicing-in-ruby-looking-for-explanation-for-illogical-behaviour-taken-fro > and here: > http://stackoverflow.com/questions/3219229/why-does-array-slice-behave-differently-for-length-n And discussed in these threads: * http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/368268 which includes this post (second in the thread) by Matz: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/368271 "foo"[3,1] is "" since when index is within the string, the sought length will be rounded to fit in the size. And 3 (which equals to the length of the string) is considered as touching the end of the string, so the result length is zero. [Which I think is useful in remembering the behaviour.] Full thread in one piece is here: http://www.ruby-forum.com/topic/215481 and here http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/f09c65251c72ab6/9a125107e3186534?pli=1 * http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/369649 Full thread in one piece is here: http://www.ruby-forum.com/topic/216796