Attr_accessor and reader and writer convert it to normal Methods style!

Hello,

How can i express the attributes methods using normal method styles (the
long coding way) to define them?

attr_accessor :name
attr_writer :name
attr_reader :legs, :arms

My own try is below. If I'm wrong, then correct it for me by re-typing
it.

My answer is:

def name=(name)
    @name = name
  end
  def name=(legs,arms)
    @name = legs, arms
  end

  def name
    @name
  end

Thank you!

···

--
Posted via http://www.ruby-forum.com/.

These are the equivalent of...

# attr_accessor :name
def name= value
  @name = value
end

def name
  @name
end

# attr_writer :name
def name= value
  @name = value
end

# attr_reader :legs, :arms
def legs
  @legs
end

def arms
  @arms
end

Henry

···

On 27/07/2012, at 1:09 PM, Ruby Sea wrote:

How can i express the attributes methods using normal method styles (the
long coding way) to define them?

attr_accessor :name
attr_writer :name
attr_reader :legs, :arms

Henry Maddocks wrote in post #1070351:

···

On 27/07/2012, at 1:09 PM, Ruby Sea wrote:

Thank you for the great answer :slight_smile:

--
Posted via http://www.ruby-forum.com/\.