Mega Code Archive

 
Categories / Ruby / Class
 

Use attr_reader to add a new attribute and use initialize method to set it

class Employee       attr_reader :name       def initialize(name)               @name = name        end end employee1 = Employee.new("Aneesha") puts employee1.name