From: Rick DeNatale Date: 2007-05-11T03:20:37+09:00 Subject: Re: What's the most ruby-ish way to write this python code? On 5/10/07, Robert Klemme wrote: > On 09.05.2007 21:02, Drew Olson wrote: Here's another way to do it: letters = ('a'..'z').to_a word = 'word' ans = [] (0..word.size).each do |i| letters.each do |c| ans << word.sub(/.{#{i}}/, "\\0#{c}") end end print ans.join("\n") or as an enumerator: class Wordgen include Enumerable attr_accessor :word Letters = ('a'..'z').to_a def initialize(word) self.word = word end def each (0..word.size).each do |i| Letters.each do |c| yield word.sub(/.{#{i}}/, "\\0#{c}") end end end end Wordgen.new("word").each do |ans| p ans end -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/