Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #1980

string/array slices

From Patrick Tyler <patrick.a.tyler@gmail.com>
Newsgroups comp.lang.ruby
Subject string/array slices
Date 2011-03-30 12:34 -0500
Organization Service de news de lacave.net
Message-ID <303f109bd62c19b354717039ac8af1a8@ruby-forum.com> (permalink)

Show all headers | View raw


Hello,

I know that this has been covered a bit here:
http://www.ruby-forum.com/topic/186437 but I'm still not certain that I
understand.

s = "foo"

s[3] is nil, like I would expect.

s[3,0] is "", instead of nil.
s[4,0] is finally nil.

I don't understand how I'm indexing '3' in the context of [3,0] and
getting anything but nil.
Since s[3] is already nil in the first place.

Same for arrays:

a = [:one, :two]

a[2] is nil
a[2,0] is an empty array ??
a[3,0] is finally nil though.

I understand that in the docs these are special cases and they're not
preventing me from working or anything like that.  I am just curious to
understand the why/how about them working this way.

Thank you!

-- 
Posted via http://www.ruby-forum.com/.

Back to comp.lang.ruby | Previous | NextNext in thread | Find similar | Unroll thread


Thread

string/array slices Patrick Tyler <patrick.a.tyler@gmail.com> - 2011-03-30 12:34 -0500
  Re: string/array slices 7stud -- <bbxx789_05ss@yahoo.com> - 2011-03-30 13:08 -0500
    Re: string/array slices Gary Wright <gwtmp01@mac.com> - 2011-03-30 16:22 -0500
      Re: string/array slices 7stud -- <bbxx789_05ss@yahoo.com> - 2011-03-30 20:03 -0500
        Re: string/array slices Adam Prescott <adam@aprescott.com> - 2011-03-31 02:17 -0500
  Re: string/array slices 7stud -- <bbxx789_05ss@yahoo.com> - 2011-03-30 13:24 -0500
    Re: string/array slices Gary Wright <gwtmp01@mac.com> - 2011-03-30 15:31 -0500
      Re: string/array slices 7stud -- <bbxx789_05ss@yahoo.com> - 2011-03-30 19:55 -0500
  Re: string/array slices Patrick Tyler <patrick.a.tyler@gmail.com> - 2011-03-30 14:42 -0500
  Re: string/array slices Patrick Tyler <patrick.a.tyler@gmail.com> - 2011-03-30 16:16 -0500
    Re: string/array slices Ross Harvey <chaos@ross.aero> - 2011-03-30 16:37 -0500
      Re: string/array slices Patrick Tyler <patrick.a.tyler@gmail.com> - 2011-03-30 19:45 -0500
  Re: string/array slices Patrick Tyler <patrick.a.tyler@gmail.com> - 2011-03-30 16:46 -0500

csiph-web