Could someone explain what is going on with the ruby code below?

I’m just not understanding the documentation or how I can access the name instance variable of a class.

class Person
  attr_reader :name
  attr_writer :name
  def initialize(name)
    @name = name

These are attribute accessors. Otherwise, you wouldn’t be able to read or change name directly.
For example, if you remove attr_reader and then try to print, you will get an error.

1 Like