From: William James Date: 2009-02-11T16:43:48+09:00 Subject: Re: how to do the recursion Li Chen wrote: > William James wrote: > > > def dec_to_binary num, result = [] > > result << > > if num.odd? > > 1 > > else > > 0 > > end > > if num < 2 > > result.reverse.join "" > > else > > dec_to_binary num/2, result > > end > > end > > > > > > p dec_to_binary 254 > > > Hi Will, > > I have one more question about the method call: > > When you define method dec_to_binary, you pass two parameters. > But when you call the method, you only provide one parameter. > > Surprisingly Ruby doesn't complain it. How to explain this seemly > inconsistancy? > > Thanks, > > Li I told dec_to_binary to use the default value [] for result when no value for result is passed to the function: def dec_to_binary num, result = [] ^^^^