Li Chen wrote: > Hi all, > > I modify James' code and want to return a hash with all values set to > 0. But I only get an empty hash. I wonder what is wrong with my codes. > > Thanks, > > Li > > def table(array,word_size=1,word='') > hash_table=Hash.new(0) > > array.each do |e| > > if word_size==1 > hash_table["#{word+e}" ]=0 > else > table(array,word_size-1,word+e ) > end > end > return hash_table > end > > ###################### > array=['A','C','G','T'] > p table(array,2) > > > > ### here is ressults:### > >>ruby table2.rb > {} >>Exit code: 0 Method calls are replaced in your code by the method's return value. The recursive calls to table() are replaced with something. What? A hash with various keys and values. But your code essentially does this: hash_table = {} if false # else {"A" => 0} end puts hash_table -- Posted via http://www.ruby-forum.com/.