extending models with statistic capabilities


I have several models in my app which contain several numerical attribute.

Ex.: stock model; attributes: bid, ask, value,…

todays_values_of_Google = [ [#Stock: id=1, bid = 1.5, ask = 1.5, value = 1.5, time=…, …], [#Stock: id=2, bid = 1.45, ask = 1.5, value = 1.45,…],… ]

Now I would like to have some statistics. I saw the possibility of open the array class and add some functions like:

Class Array

def mean; blabla ; end;


But I would like to have the option of telling the attribute on which to calculate the mean.

So what would be the best practice for this as I need this on several model?

1.) A module? How?

Maybe this

def mean(array,attr); #calculate over all items of arrays attribute attr… ; end

2.) Modify Classes? Where to do it so all model can access the “new” methods of Array (for example)

3.) Somethink else?

Thanks for any help