-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.rb
48 lines (36 loc) · 766 Bytes
/
user.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
class User
# same as using getters and setters
attr_accessor :name, :email
# class constructor called everytime a object is created
def initialize(name, email)
# @ symbol signifys that it's an instance variable
@name = name
@email = email
end
def walk
puts "I'm just walking"
end
def run
puts "Hey i'm running!"
end
# accessor methods
def get_name
@name
end
def set_name(name)
@name = name
end
# a different way to call a setter
# user.set_name = "newName"
def set_name=(name)
@name = name
end
end
user1 = User.new("Foo", "foo@bar.com")
user2 = User.new("Bar", "bar@foo.com")
puts user1.run
puts user2.walk
puts user1.get_name
user1.set_name("Tal")
puts user1.get_name
puts user1.email