From: Paul Roche Date: 2010-10-07T07:03:19+09:00 Subject: Re: Error when using class variables with operators Jeremy Bopp wrote: > On 10/6/2010 2:58 PM, Jeremy Bopp wrote: >>>>> | >>> >>> def self.on_target?(mltn) >>> >> class variables shared among all instances of your class, which is >> end >> @target2. I found these notations a little hard to remember at first, >> but you'll find that defining class variables is pretty rare and that >> you can usually just use @variable. :-) > > Hmm. Looking closer at what you're trying to do, I see that you do need > the class variables in your current implementation. The problem is that > I can't figure out why you are trying to use a class method (on_target?) > for this rather than an instance method. It looks like Stefano is also > confused about what you're trying to do here. > > Please understand that you are mixing together class and instance > methods. For now you should probably stick to instance methods since > they are more common: > > class MyClass > def my_instance_method > ... > end > end > > Rather than... > > class MyClass > def self.my_class_method > ... > end > end > > > Once you have a handle on instance methods, understanding class methods > and how they differ from instance methods will be easier. > > -Jeremy Thanks guys for the help. Stefano, I stuck a 'p' in and I got a nil. Jeremy I understand where you are coming from when you say stick to instance methods before using class methods. However I need to make one method a class method (it's more complex than the example I gave above). I will then be calling a method from here (presumingly this has to be a class method too?) Thanks for the patience, I'm slow on the uptake -- Posted via http://www.ruby-forum.com/.