Is there a Ruby library version problem with my ISP ?

J

Josselin

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

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
 
M

Morton Goldberg

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
letter = ('A'..'Z').to_a

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


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top