# タイヤクラス
class Tire
attr_reader :size, :type
def initialize(size, type)
@size = size
@type = type
end
def info
"#{@size}インチ #{@type}タイヤ"
end
end
# ブレーキクラス
class Brake
attr_reader :type
def initialize(type)
@type = type
end
def apply
puts "#{@type}ブレーキをかけました!"
end
end
# GPSナビゲーションクラス
class Navigation
def calculate_route(destination)
puts "#{destination}への最適ルートを計算中..."
sleep(1)
puts "ルートが見つかりました!"
end
end
# 拡張された車クラス
class AdvancedCar
def initialize(engine, tire_size: 17, tire_type: 'ラジアル', brake_type: 'ディスク')
@engine = engine
@tires = Array.new(4) { Tire.new(tire_size, tire_type) }
@brake = Brake.new(brake_type)
@navigation = Navigation.new
end
def start
puts "車の準備を開始します..."
puts "タイヤ: #{@tires.first.info} x 4本"
puts "ブレーキ: #{@brake.type}"
@engine.start
end
def stop
@brake.apply
@engine.stop
end
def navigate_to(destination)
@navigation.calculate_route(destination)
end
end
# 使用例
my_car = AdvancedCar.new(
ElectricEngine.new,
tire_size: 18,
tire_type: 'スポーツ',
brake_type: 'カーボン'
)
my_car.start
my_car.navigate_to("東京駅")
my_car.stop