From: Kenneth McDonald Date: 2008-09-10T09:37:04+09:00 Subject: Re: yield/block question Perfect, just what I was looking for. Thanks, Ken On Sep 9, 2008, at 7:17 PM, Serabe wrote: > What about this? > > class Array > def each_leaf(&block) > each do |x| > case x > when Array: x.each_leaf &block > else block.call x > end > end > end > end > > arr = [[1,2], 3, [[4]]] > result = 0 > arr.each_leaf{|n| result += n} > > puts result > > Kind regards, > > Serabe > > P.D. Sorry for no more explanation, but I'm really tired (2:23 am > right now). > > -- > http://www.serabe.com >