-
Notifications
You must be signed in to change notification settings - Fork 0
/
improvement_2.rb
46 lines (34 loc) · 938 Bytes
/
improvement_2.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
class TelcoProvider
attr_accessor :provider_name
Provider = Struct.new(:name, :homepage, :email, :telephone_number)
PROVIDERS = [
Provider.new(:maxis, 'maxis.com.my', '[email protected]', '03-12345678'),
Provider.new(:digi, 'digi.com.my', '[email protected]', '03-12344321'),
Provider.new(:celcom, 'celcom.com.my', '[email protected]', '03-87654321')
]
def initialize(provider_name)
@provider_name = provider_name
end
def email
provider.email
end
def homepage
provider.homepage
end
def telephone_number
provider.telephone_number
end
def is?(provider_name)
provider_name == provider.name
end
private
def provider
@provider ||= PROVIDERS.find { |provider| provider_name == provider.name }
end
end
telco = TelcoProvider.new(:maxis)
telco.telephone_number # =>
telco.homepage # =>
telco.email # =>
telco.is?(:maxis) # =>
telco.is?(:digi) # =>