I’ve declared a method inside the string class that has to answer the
amount of “X” and “2” chars in a string. The string is ALWAYS gonna be
15 chars size. The code is the following:
# DAME VARIANTES def variantes @variantes = 0 15.times do |@cont| if (self[@cont] == "2" || self[@cont] == "X") @variantes = @variantes + 1 end end return @variantes end
cadena = “XX222XX222XX1X2”
And the last line ALWAYS ANSWERS a CERO. Why? Why it doesn’t enter the
if statement inside the method?