Li Chen wrote:
> 7stud -- wrote:
>> Look at what happens when the array has one element:
>> 
>> data = ["A"]
>> result = table(data, 2)

Hi,

Given that I can print out the hash but the return one in main program 
is empty, I still don't figure how to return the hash I want.


Li


def table(array,word_size=1,word='')

  hash_table=Hash.new(0)
  array.each do |e|
    if word_size==1
      word+ e
      hash_table[word+e]=0
    else
            table(array,word_size-1,word+e )
    end
 end
   hash_table.each {|k,v|print k, "=>",v,"\n"}# it looks like I have a 
hash here
                                              # and I can print out the 
results
end

######################
array=['A','C','G','T']

 p table(array,2).each {|k,v|print k, "=>",v,"\n"}


######output results########


>ruby table2.rb    
AA=>0
......
TG=>0
{}
>Exit code: 0


-- 
Posted via http://www.ruby-forum.com/.