Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Re: subarray using [1,-1] returns nil.
cliveharber
8/24/2007 8:43:00 AM
Hi Todd
The operation b = a[1,-1] is a slice operation where the first index is the start point and the second is the length of the array that you are retrieving - this is why you are getting nil for 'b' - the way to do this would be to use an inclusive range like this b = a[1..-1] - this will return the results that you expect.
---- Todd Burch <promos@burchwoodusa.com> wrote:
> a = %w(a b c d e f g) ;
> puts "a.length = #{a.length}" ;
>
> b = a[1,-1] ;
> puts "b.length = #{b.length}" ;
>
> Why is array b nil after the subarray? I expect it to be equal to "a"
> minus the first element.
>
> Todd
> --
> Posted via
http://www.ruby-...
.
>
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Re: subarray using [1,-1] returns nil.
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password