From: Joel Pearson Date: 2013-01-29T18:39:04+09:00 Subject: Re: Please explain in English Ryan Davis wrote in post #1094171: > On Jan 28, 2013, at 10:01 , Joel Pearson wrote: > >> def count_words(string) >> res = {} >> string.downcase! >> string.scan( /\w+/ ).uniq.each{ |word| res[word] = >> string.scan(/\b#{word}\b/).size } >> res >> end > > This modifies the argument coming in. Don't ever call downcase! or other > mutating methods on an argument or you'll wind up in debugging hell. > Make a copy instead: > > string = string.downcase Thanks, I thought that those two things were equivalent. Doesn't string = string.downcase overwrite the argument string anyway? -- Posted via http://www.ruby-forum.com/.