From: Logan Capaldo Date: 2007-07-29T20:25:51+09:00 Subject: Re: how can i use a ruby class in object way ------=_Part_11501_6210631.1185708352470 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On 7/29/07, Guo Yangguang wrote: > > Sorry ,i am not show it very clear.Please read this example again: > > class Test > def Test.say_hello > puts "Hello from #{self.name}" > puts "hello from #{self.class}" > end > say_hello #i don't understand here > end Try this on for size: class Test puts "Self is" p self puts "Test is" p Test puts "Test == self?" p( Test == self ) def Test.say_hello puts "Hello" end say_hello Test.say_hello self.say_hello end In the body of a class block, self is the class. That's why you can call the "class" method right there, after defining it. Normally,we can use a class anyplaces after defining it ,but in this > example,i use a classmehod immediately after defining it "in class > context".This is valid.I means calling a classmethod(not an intance > method) in a class defintion--not after defining that class--is valid > .Can you explain it for me? thank you ! > > > > > > > > > Robert Dober wrote: > > On 7/29/07, Guo Yangguang wrote: > >> end > >> say_hello > >> end > >> > > It is not completely clear what you want to achieve but some remarks > > might be helpful > > > > class Test > > def initialize > > e="e" # this code is not realy useful, e is a scope local > > variable that will be thrown away, you probably want to do this: > > @e = "e" # this is an instance variable > > end > > > > attr_accessor :e # for some tests below > > > > def Test.say_hello > > ... > > end > > say_hello > > end > > > > Test.say_hello > > aTest = Test.new > > puts aTest.e > > aTest.e = 42 > > puts aTest.e > > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_11501_6210631.1185708352470--