From: 7stud -- Date: 2012-11-28T04:20:16+09:00 Subject: Re: Novice: Understanding instance 'variables' and methods First, I suggest that you learn more than one variable name. Naming everything in your code test/Test/:test is just going to confuse you. > I then added the 'attr_accessor :test' which presumably added a test= > method, leaving the original 'test' method. Writing attr_accessor :name inside a class is equivalent to writing: def name #getter @name end def name=(val) #setter @name = val end And you call the 'name=' method like this: d.name = 10 ruby ignores the space between 'd.name' and the '=' sign. Once again, if you redefine a method it will overwrite an existing method: class Dog attr_accessor :name end d = Dog.new d.name = 'Sam' puts d.name --output:-- Sam But see what happens here: class Dog attr_accessor :name def name 'hello' end end d = Dog.new d.name = 'Sam' puts d.name --output:-- hello The line attr_accessor :name tells ruby to create the methods: def name #getter @name end def name=(val) #setter @name = val end ...which ruby does. Next ruby sees the definition: def name 'hello' end in the Dog class, and that name method overwrites the name method that ruby created. -- Posted via http://www.ruby-forum.com/.