From: "Daniel Gaytán" Date: 2010-09-20T13:54:49+09:00 Subject: Re: how to get Mycompute.sum([1,2,3,4]).mean=2.5? --001636c5b7051d21460490a9b6a9 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I don't know if you tried to say how you can write a code that accepts Mycompute.sum([1,2,3,4]).mean ... not to know if the mean of an array is th= e specified as argument: "Mycompute.sum([1,2,3,4]).mean=3D2.5?" If you need to accept the first approach, you should better extend the Arra= y class: class Array def mean self.inject(0){|s,i|s+i}/(self.size.to_f) end end [1,2,3,4].mean # =3D> 2.5 Since the sum doesn't have mean, but a set of values. I hope I have helped in a way with my answer. Daniel Gayt=E1n 2010/9/19 Pen Ttt > class Mycompute > def self.sum(a) > a.inject(0){|s,i|s+i} > end > def self.mean(a) > a.inject(0){|s,i|s+i}/(a.size.to_f) > end > end > Mycompute.sum([1,2,3,4]) > =3D> 10 > Mycompute.mean([1,2,3,4]) > =3D> 2.5 > > how can i get Mycompute.sum([1,2,3,4]).mean=3D2.5? > -- > Posted via http://www.ruby-forum.com/. > > --001636c5b7051d21460490a9b6a9--