ruby - 未初始化的常量 Van (NameError)
问题描述
我正在尝试编写一些功能,使我可以将坏掉的自行车带到车库进行修理,而在实现此功能时,我遇到了这个问题。我知道这通常是因为它找不到该文件,但对如何修复它已经没有想法了。如果您需要任何其他代码,请告诉我,但我认为这将是所需的所有代码。
坞站.rb:
require_relative 'Bike'
require_relative 'van'
require_relative 'garage'
class DockingStation
attr_reader :dock, :max_dock, :DEFAULT_CAPACITY
DEFAULT_CAPACITY = 20
def initialize(capacity = DEFAULT_CAPACITY)
@max_dock = capacity
@dock = []
end
def release_bike
if !empty?
@dock.each_with_index do |bike, index|
if bike.working?
@dock.delete_at(index)
return bike
else
raise "Bike is broken"
end
end
else
raise "No bikes to release"
end
end
def dock_bike(bike, working = true)
if !full?
@dock << bike
else
raise "Too many bikes"
end
end
def show_dock
@dock.each do |el|
return el
end
end
def van_takes_broken_bikes(van)
puts @dock
@dock.each_with_index do |bike, index|
if bike.working? == true
van.storage.append(bike)
else
van.storage.append(bike)
end
end
end
private def full?
@dock.length == @max_dock
end
private def empty?
@dock.length == 0
end
end
dock = DockingStation.new
bike = Bike.new
van = Van.new
bike.report_broken
dock.dock_bike(bike)
dock.van_takes_broken_bikes(van)
范.rb:
require_relative 'dockingstation'
require_relative 'garage'
class Van
attr_reader :storage
def initialize
@storage = []
end
def take_broken_bikes_to_garage(bikes)
end
end
解决方案
推荐阅读
- visual-studio - Visual Studio Xamarin Forms App 无法在 iPhoneSimulator 上启动
- php - 运行 php 脚本循环时如何监控剩余时间?
- ajax - axios put request 和 symfony 控制器
- c# - .MSG 文件元数据提取 - 发件人 SMTP 电子邮件
- android - kotlin中带有val的Gson序列化错误
- javascript - Uploadcollection发送文件但无法打开?
- javascript - 如何处理只点击一次
- 反应中的项目
- android - 如何使 AlertDialog 显示在屏幕边缘附近
- javascript - 如何在 typescript 2.9 中读取 HashMap
- java - Java 输入流加密