Ruby Ruby Objects and Classes Variables and Methods Variables and Methods

Name variable not found

name variable not found

class.rb
class Name

  name = Name.new


  def initialize(title)
    @title = title
  end 
  def first_name
    "Metal"
  end

  def last_name
    "Robot"
  end
end

1 Answer

Antonio De Rose
Antonio De Rose
20,866 Points
class Name

  name = Name.new #this will have to come out of the class
#that is the main purpose of instantiating, accessing a class variables from outside the class
#that too you are missing 2 things in it, one is the brace, and the title argument

  def initialize(title)
    @title = title
  end 
  def first_name
    "Metal"
  end

  def last_name
    "Robot"
  end
end