urgent help please!!

words = "Kid games need to be both fun and educational. Aimed at ages
pre-K through middle school, safe environment to discover their
abilities and learn new skills with interactive and fun computer
games. Our games build skills in math, logic, memory, vocabulary,

alphabet, spelling, geography, computer skills, color identification,
shape identification and other various problem solving. Our commitment
to parents, teachers, and kids, is to connect earning and skill
building with a sense of challenge, fun, and self esteem."

word_arry = words.split(" ")

count=0
line_text="<="
word_arry.each {|word|
count+=word.length
if count > 40
count=0
line_text+="=>\n<="+word+" "

else
#puts count.to_s
end_txt = (count > 38) ? word : word+" "
line_text+=end_txt
end
}
line_text+="=>"

puts line_text

following is the method which trims the string which passes as an
argument and trims if it's length is greater than collength.

def trimstring(string, collength)
    if(string.length>collength)
        @str = ""
        col = 0
        @lines = 0..(string.length/collength)
        for @line in @lines
          @str += string[col,collength] + "<br>"
          col = col+collength
        end
        return @str
    else
        return string
    end
  end