Files
  • main.rb
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# classes & objects
class Employee 
  # initializing method used when creating new objects
  def initialize(full_name, id, dept)
    @full_name = full_name
    @id = id
    @dept = dept
  end 
  # use when you need to print out their full name
  def getFull_Name
    @full_name
  end
  # use when you need to print out their id
  def getId 
    @id
  end
  # use when you need to print out their department
  def getDept
    @dept
  end
end

# create the new objects: emp101 & emp102 and assign them default values
emp101 = Employee.new("John Doe", 101, "HR")
emp102 = Employee.new("Jane Smith", 102, "Engineering")

# put information on the screen
puts "#{emp101.getFull_Name} works in the #{emp101.getDept} department."
puts "Employee ID #{emp102.getId} works in the #{emp102.getDept} department."
ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-linux]