Need an explaination what ruby do with a method

Hi, can someone explain me what ruby do here?:

class Example

 attr_accessor :example_v

  def example_v=(example_v)

    code
  end

end
http://stackoverflow.com/questions/4370960/what-is-attr-accessor-in-ruby

The following code

  def example_v=(example_v)    @example_v = example_v + 1 # I changed this line a bit  endWill overwrite the code that you already created using an attr_accessor.

attr_accessor :example_v is actually meta programming and before the code is executed it is (I assume) replaced (you will never see the replaced code) with the following code by Ruby:

Code:
  def example_v    @example_v  end  def example_v=(example_v)    @example_V = example_v  end
Ahh, i understand now, thanks very much.
In addition (for anyone else who may read this thread):

The code shown above is how Ruby handles Properties.

A Property is a special kind of class member which generally has two associated methods; a "getter" and a "setter".  If the property is read-only, then it only has a getter method.  If the property is write-only, then it only has a setter method.  Most of the time the getter simply returns the value of an associated private class variable and the setter simply sets this internal variable to a supplied value.

For example, here is a class for a "person" with a read-only "name" and a read-write "age":

class Person
   def initialize(personsName, initialAge)
      @name = personsName
      @age = initialAge
   end

   def name #getter only

      @name #return name

   end

   def age #getter

      @age #return age

   end

   def age=(value) #setter

      @age=  value #assign age

   end

end

Ruby then allows you to short-cut this code using attributes assigned to identifiers.  So the attribute "attr_accessor" equates to writing a getter and setter method for the identified local variable.  And the attribute "attr_reader" equates to writing only a getter method for the identified local variable.  So the following "person" class is equivalent to the one above:

class Person

   attr_reader      :name

   attr_accessor  :age

   def initialize(personsName, initialAge)
      @name = personsName
      @age = initialAge
   end

end
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/need-an-explaination-what-ruby-do-with-a-method.18397/