From: Pen Ttt Date: 2010-09-22T09:40:00+09:00 Subject: Re: how to get Mycompute.sum().mean=2.5? require 'rubygems' require 'mysql' class Analyse def self.get(from,to) open('/tmp/result','w') do |wfile| dbh = Mysql.real_connect("localhost", "root", "******") dbh.query("use stock;") result=dbh.query("select symbol,date,open,high,low,close \ from `#{symbol}` where (date > from and date< to) order by date asc;") compute=[] result.each{|row| wfile.puts row.join(";")} end end def self.mean amean=[] open('/tmp/result','r'){|rfile| line=rfile.readlines line.each{|item| amean<< item.chomp.split(";")[-1].to_f }} amean=amean.compact amean.inject(0){|s,n| s+n}/(amean.size.to_f) end end end input Analyse.get("2010-01-1","2010-09-1") can get a file /tmp/result again input Analyse.mean can get what i need, but Analyse.get("2010-01-1","2010-09-1").mean can't work, would you mind to tell me how to fix the mean method to make Analyse.get("2010-01-1","2010-09-1").mean can work?? -- Posted via http://www.ruby-forum.com/.