首页 > 解决方案 > 未初始化的常量 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

标签: rubyclass

解决方案


推荐阅读