From: Dmitry Buzdin Date: 2006-11-17T23:30:06+09:00 Subject: Re: Newbie issue Check the manual str[0] will return a numeric representation of the character what You need is str[0,1] one character starting from the first position. Try this: class String def variantes @variantes = 0 Range.new(0, 14).each { |i| if (self[i,1] == "2" || self[i,1] == "X") @variantes = @variantes + 1 end } return @variantes end end str = "XXXXX22222XXXXX" puts str.variantes Dmitry