From: Robert Klemme Date: 2010-10-13T20:43:24+09:00 Subject: Re: Recursion in a class method On Wed, Oct 13, 2010 at 1:24 PM, Iain Barnett wrote: > Hi, > > If I've written a class method that calls itself recursively is there a problem or any difference between doing something like this: > > class << self >  def mymeth( n ) >    blah blah... > >    mymeth( n + 1) >  end > end > > > as opposed to this? > > class << self >  def mymeth( n ) >    blah blah... > >    Classname.mymeth( n + 1 ) >  end > end > > I wrote something a few minutes ago in the first way, and it works (those virgin sacrifices must be working their magic) but wondered if that's A Really Bad Thing To Do™, or if it's more like wearing socks with sandals on a warm day? Even simpler irb(main):006:0> class X irb(main):007:1> def self.r(n) p n; r(n-1) if n > 0 end irb(main):008:1> end => nil irb(main):009:0> X.r 5 5 4 3 2 1 0 => nil You do not need "Classname." because "self" is the class instance. Actually placing the class name could do more harm than good (think of "private" and renaming the class). Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/