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 <myocean135 / yahoo.cn>

> 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/.
>
>