From: Pen Ttt Date: 2010-09-25T10:45:11+09:00 Subject: Re: to make dot method dot method work? 1. why are you still assigning to @@result? if i change code1 into code2 code1 class Mycompute def initialize(str) @str=str end def values @@result=@str def @@result.up self.upcase end @@result end def up @@result.upcase end end code2 class Mycompute def initialize(str) @str=str end def values @result=@str def @result.up self.upcase end @result end def up @result.upcase end end code2 can only get : Mycompute.new("Abc").values => "Abc" irb(main):017:0> Mycompute.new("Abc").up NoMethodError: undefined method `upcase' for nil:NilClass from (irb):13:in `up' from (irb):17 from :0 irb(main):018:0> Mycompute.new("Abc").values.up => "ABC" code1 can get Mycompute.new("Abc").values #=> "Abc" Mycompute.new("Abc").up #=> "ABC" Mycompute.new("Abc").values.up #=> "ABC" 2.here is my real code real code1 require 'rubygems' require 'mysql' require 'date' class Analyse @@result=[] def self.vol(symbol,cycle) cycle=cycle.to_i dbh = Mysql.real_connect("localhost", "root", "******") dbh.query("use stock;") result=dbh.query("select symbol,date,open,high,low,close from `#{symbol}` order by date asc;") compute=[] result.each{|row| compute< cycle-2 then if row[4].to_f==0 then row[6]="nil" else mymax=[] mymin=[] for i in idx-cycle+1..idx mymax< cycle-2 then if row[4].to_f==0 then row[6]="nil" else mymax=[] mymin=[] for i in idx-cycle+1..idx mymax< # Analyse.vol("c","5").mean => 7.62 what i want is real code3 which can get 1)Analyse.vol("c","5") can get output such as c;2010-09-09;3.89;3.95;3.88;3.91;4.19 c;2010-09-10;3.92;3.94;3.9;3.91;4.19 c;2010-09-13;3.96;4.01;3.96;3.99;4.97 c;2010-09-14;3.98;3.99;3.91;3.94;4.70 c;2010-09-15;3.92;3.93;3.9;3.92;3.35 c;2010-09-16;3.89;3.98;3.88;3.97;3.35 c;2010-09-17;4;4.02;3.95;3.95;3.61 not => # 2)Analyse.vol("c","5").mean can get => 7.62 not NoMethodError: undefined method `mean' for nil:NilClass would you mind to help me to write code3? -- Posted via http://www.ruby-forum.com/.