Defining and Using an Employee Class
require 'date'
class Employee
attr_reader :name, :hiredate, :salary
attr_writer :salary
def initialize(n, h, s)
@name = n
@hiredate = h
@salary = s
end
end
a_date = Date.new(2006, 6, 21)
me = Employee.new("Barry Burd", a_date, 1000000.00)
a_date = Date.new(2006, 6, 25)
you = Employee.new("Harriet Ritter", a_date, 50000.00)
print me.name
printf("\t%s\t%5.2f\n", me.hiredate, me.salary)
print you.name
printf("\t%s\t%5.2f\n", you.hiredate, you.salary)
me.salary += 1000.00
print me.name
printf("\t%s\t%5.2f\n", me.hiredate, me.salary)
Related examples in the same category