From: Brian Candler Date: 2009-10-13T18:26:26+09:00 Subject: Re: When use self.method_name and when only method_name? Joshua Muheim wrote: > Just a small newbie question: When calling a method inside an object, I > should always use self.method_name for good style, right? I know that I > could always only use "method_name", but it's a bit prone to errors > because I could have also a local variable called "method_name", and > when I use "self." I always call the method, and not a potentially > available local variable. It's good style to keep methods small. Remember that every method starts with a clean sheet of local variables - they *never* propagate in from outside - so it's obvious by inspection whether a name is a local variable or not. But there is a much larger class of errors such as simple typos: self.method_nmae slef.method_name You'll need unit tests to counter these; and once you have them, these will also cover other logic errors including the accidental shadowing of a method with a local variable as you describe above. BTW, I still sometimes write foo = xxx when I mean to call the method, self.foo = xxx I suppose writing 'self.' everywhere would make that less likely - but I'd still say it's better to have good unit tests. -- Posted via http://www.ruby-forum.com/.