2009/10/26 salai <sayakyi / gmail.com>: > Dear Rubyist, > > I want to count array list [1,2,3,[4],5] ---> # 5 leaves > but I always get sum_of_array. > > Where did I do wrong? > > > ¨Âåæ áòòáùßìåáöå± óõíßïæßáòòáù The method should have the same name as the one you call below ("elem.sum_of_array"). > ¨Âåó > ¨Âåìæ®åáãèûüåìåí> ¨Âåìåí®ëéîäßïæ¿¨Áòòáù© > ¨Âåó «½ åìåí®óõíßïæßáòòá> ¨Âìó> ¨Âåó «½ åìåí > ¨Âîä > ¨Â > ¨Âåôõòòå> ¨Âîä > > def number_of_leaves > ¨Âåìæ®éîêåãô¨°©ûüáãã¬ø> ¨Âø®ëéîäßïæ¿¨Áòòáù> ¨Âãã «½ ø®îõíâåòßïæßìåáöåó > ¨Âìó> ¨Âãã «½ The line above should read acc += 1. You could even simplify that as acc += (x.number_of_leaves rescue 1) > ¨Âîä > ¨Â > ¨Âîä Not sure what your issue is exactly. Please show the complete code along with expected results. The code you presented cannot be the real code because at least the class declaration is missing. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/