add TRIE logic using ruby hash