From: Li Chen Date: 2009-02-11T10:32:27+09:00 Subject: Re: how to do the recursion William James wrote: >> If you found Pascal's code somewhat puzzling, let me explain. > His customary language is CLisp, so when he deigns to dabble > in Ruby, he tries to make his code look lispish. Hi Will, Thank you for your rubyish code. Yes. I am really confused when I read Pascal's codes. I don't think nowhere in Pixaxe ever mentions about function BUT only methods and objects! I have questions about two code lines: 1) result << What does it mean, concatenate nothing??? 2) num.odd? When I run the code Ruby complains about #odd?. I check the class Fixnum and I can't find #odd? So I change it to num%2==1 and Ruby runs happily. Thanks, Li > > 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 -- Posted via http://www.ruby-forum.com/.