Fredkin trie algorithm in Ruby