Is there a Ruby library version problem with my ISP?

I am running locally without any problem the following simple statement (detect first non-zero value...)

nb_cities_alphabet = [7, 21, 20, 1, 4, 1, 18, 3, 5, 1, 4, 48, 21, 8, 0, 31, 6, 10, 47, 7, 0, 1, 0, 0, 0, 0]

      i = nb_cities_alphabet.index(nb_cities_alphabet.detect {|x| x > 0})
      letter = ('A'..'Z').to_a[i]

but when running it with my ISP I get the error message :

NoMethodError : undefined method `detect' for false:FalseClass

any idea why this error ? and why I don't get it locally ?

if it's actually a lib problem... any trick to replace it
thanks a lot

joss

I don't have any idea about what's going wrong with your server, but you might try the following code. It's a little more robust and efficient than what you are using now.

<code>
nb_cities_alphabet = [7, 21, 20, 1, 4, 1, 18, 3, 5, 1, 4, 48, 21, 8, 0, 31, 6, 10, 47, 7, 0, 1, 0, 0, 0, 0]

i = ?* - ?A
nb_cities_alphabet.each_with_index do |e, k|
    if e > 0
       i = k
       break
    end
end
letter = (i + ?A).chr
</code>

It will assign an asterisk ('*') to letter when there are no non-zero items in nb_cities_alphabet, which help with debugging.

Regards, Morton

···

On Dec 20, 2006, at 5:30 PM, Josselin wrote:

I am running locally without any problem the following simple statement (detect first non-zero value...)

nb_cities_alphabet = [7, 21, 20, 1, 4, 1, 18, 3, 5, 1, 4, 48, 21, 8, 0, 31, 6, 10, 47, 7, 0, 1, 0, 0, 0, 0]

     i = nb_cities_alphabet.index(nb_cities_alphabet.detect {|x| x > 0})
     letter = ('A'..'Z').to_a[i]

but when running it with my ISP I get the error message :

NoMethodError : undefined method `detect' for false:FalseClass

any idea why this error ? and why I don't get it locally ?

if it's actually a lib problem... any trick to replace it
thanks a lot