From: gotoken@... (GOTO Kentaro) Date: 2000-02-15T14:17:50+09:00 Subject: [ruby-talk:01366] Re: nice sample for functional stuff In message "[ruby-talk:01365] Re: nice sample for functional stuff" on 00/02/14, Dave Thomas writes: > module Enumerable > > # inject(n) { |n, i| ...} > def inject(n) > each { |i| n = yield(n, i) } > return n > end > > def sum > inject(0) {|n, i| n += i } > end > end That is not bad though, I was interested in how I can sum up the non-numerical elements. The solution above uses an assumption such that the result is 0 if enum.size == 0 but [ruby-talk:01364] doesn't. # And, I wanted simply to use `callcc' then ;-) Thanks, -- gotoken