-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure_vehicles.rb
44 lines (35 loc) · 1.02 KB
/
configure_vehicles.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
class Vehicle
class << self
attr_accessor :engine, :wheels, :color, :interior_config
def configure
yield(self)
end
def summarize_configuration
config_summary = "The vehicle has a #{engine} engine, #{wheels} wheels, a #{color} exterior color"
config_summary += interior_config.summarize_configuration if
interior_config
puts config_summary + "."
end
def interior
@interior_config ||= Interior.new
yield(interior_config)
end
end
private
class Interior
attr_accessor :material, :color
def summarize_configuration
" and a #{material} #{color} interior"
end
end
end
Vehicle.configure do |config|
config.engine = "V6"
config.wheels = 4
config.color = "red"
config.interior do |int|
int.material = "leather"
int.color = "black"
end
end
Vehicle.summarize_configuration