5. attr_reader, attr_writer Add a new attribute with params?


I'm trying to add an attribute to the newly created method 'job', and then output the result but I don't seem to have my code right.
Can someone help me figure out how I can do this correctly?


I get this error code:
undefined method `job' for #<Context::Person:0x00000001ef0230 @name="Joe">

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

dude = Person.new("Joe")


puts dude.name

puts dude.job


The @job attribute needs to be defined in the class intialize method. Add it to the parameters and include the statement under @name. Be sure to include a job title in the instance arguments..

Once it is defined, you should be able to assign a new value.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.