Robert Klemme
10/16/2008 3:00:00 PM
On 16.10.2008 13:35, Chris Ashton wrote:
> thanks for the help, i really appreciate it, worked a treat
>
> I also need to do this:
>
> array[count + 1]
>
> array[count] returns x but array[count + 1] returns nil when i should be
> y
>
> am i totally wrong or is it something else?
Depends on count and the size of the Array. Either count is array.size
- 1 in which case array[count + 1] points after the last element. Or
your array contains nil at that position.
irb(main):001:0> a=[1,2,3]
=> [1, 2, 3]
irb(main):002:0> a.size
=> 3
irb(main):003:0> a[a.size]
=> nil
irb(main):004:0> a[0]
=> 1
irb(main):005:0> a[1]
=> 2
irb(main):006:0> a[2]
=> 3
irb(main):007:0> a[3]
=> nil
irb(main):008:0>
Cheers
robert