Why arr != arr[0] with only one element in the array?
arr is the whole Array object and arr[0] is the first element of the
array
(= 100) and these are not equal.
Yes but when the array contains only ONE element
there’s no real need to indicate the position of that element.
So i want to use arr as if it was arr[0]. But that’s no possible…
Yes but when the array contains only ONE element
there’s no real need to indicate the position of that element.
So i want to use arr as if it was arr[0]. But that’s no possible…
You have to think of the array as the chest of apples. When you have
only one apple left, the chest does not disappear. If it did, the
fact would generate a lot of confusion…
You could always run a check of the array and see how many items are in
it, if
there is only one, then do something like:
array.first
that way you don’t have to use [0].
Wayne
----- Original Message ----
From: Ronnie Aa [email protected]
To: ruby-talk ML [email protected]
Sent: Mon, February 11, 2013 8:14:24 AM
Subject: Re: firtst and only element of array (noob level)
Carlo E. Prelz wrote in post #1096281:
only one apple left, the chest does not disappear. If it did, the
fact would generate a lot of confusion…
Yes but when the array contains only ONE element
there’s no real need to indicate the position of that element.
So i want to use arr as if it was arr[0]. But that’s no possible…
You have to think of the array as the chest of apples. When you have
only one apple left, the chest does not disappear. If it did, the
fact would generate a lot of confusion…
Carlo
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.