From: Phil Date: 2004-01-14T14:31:36+09:00 Subject: What's the ruby way to avoid recursion? What is the ruby way to do this without recursion? Thanks, Phil C class FactorialCases attr_reader :count attr :cases, true def initialize(str) @pat = str @cases = [] compute_cases(str) end private def compute_cases(str) size = str.size 1.upto(size) do @pat[0..(size - 1)] = str if size > 2 then compute_cases(str.slice(0..-2)) else @cases << @pat.dup end str = str.slice(-1,1) + str.chop end str end end a = FactorialCases.new("123") a.cases.each { |value| print "Factorial pattern = ", value, "\n" } print "total ", a.cases.size, "\n"