Created
December 24, 2013 03:26
-
-
Save fenixbrassi/8108403 to your computer and use it in GitHub Desktop.
Practicing with classes methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Employee | |
attr_accessor :first_name, :last_name, :salary, :age, :months_of_service | |
def initialize(first_name , last_name, salary, age, months_of_service) | |
@first_name = first_name | |
@last_name = last_name | |
@salary = salary | |
@age = age | |
@months_of_service = months_of_service | |
end | |
#You can edit the salary & months_of_service | |
def salary=( s ) | |
@salary = s | |
end | |
def months_of_service=( ms ) | |
@months_of_service = ms | |
end | |
#first_name & last_name, age should NOT be editable | |
private | |
def first_name | |
first_name | |
end | |
def last_name | |
last_name | |
end | |
def age | |
age | |
end | |
end | |
e1 = Employee.new("Ernesto" , "Ponce", "10000 dlls", 28, 48) | |
puts e1.salary | |
puts e1.months_of_service | |
e1.salary=("25000 dlls") | |
puts e1.months_of_service=(50) | |
puts e1.salary | |
puts e1.months_of_service | |
#puts e1.first_name = "Ernie" should throw an error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment