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


#1



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?

Thanks

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
  end
  
end

dude = Person.new("Joe")

dude.job("hack")

puts dude.name

puts dude.job


#2

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.


#3

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