Skip to content

Commit 4a101fe

Browse files
committed
Adds job title class to handle null object pattern
1 parent b0ec5a5 commit 4a101fe

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

presenters/job_title.rb

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class User
2+
attr_accessor :name
3+
end
4+
5+
class NilUser
6+
7+
def name
8+
'no name'
9+
end
10+
11+
def email
12+
'no email'
13+
end
14+
end
15+
16+
class JobTitle
17+
18+
def initialize(user)
19+
@user = user || NilUser.new
20+
end
21+
22+
def user_name
23+
user.name
24+
end
25+
26+
def user_email
27+
user.email
28+
end
29+
30+
end

0 commit comments

Comments
 (0)