Ruby 初始化中的参数数目错误(给定0,应为1)

Ruby 初始化中的参数数目错误(给定0,应为1),ruby,Ruby,我将在以下网站提供教程: 我已经检查并重新检查了代码,我不明白为什么ruby没有将我的变量app\u map作为有效参数读取 我在网上搜索过类似的问题,它们确实存在,但我不明白为什么这个变量不起作用。我也不太清楚initialize是什么意思,因为我是Ruby的绝对初学者。如有任何见解,将不胜感激 #!/usr/bin/env ruby class Launcher def initialize (app_map) @app_map = app_map end #exe

我将在以下网站提供教程:

我已经检查并重新检查了代码,我不明白为什么ruby没有将我的变量
app\u map
作为有效参数读取

我在网上搜索过类似的问题,它们确实存在,但我不明白为什么这个变量不起作用。我也不太清楚
initialize
是什么意思,因为我是Ruby的绝对初学者。如有任何见解,将不胜感激

#!/usr/bin/env ruby

class Launcher

  def initialize (app_map)
   @app_map = app_map
  end

  #execute the given file using the associate app
  def run file_name
    application = select_app file_name
    system "#{application} #{file_name}"
  end

  #given a file, lookup the matching application
  def select_app file_name
    ftype = file_type file_name
    @app_map[ ftype ]
  end

  #return the part of the file name string after the last '.'
  def file_type file_name
    File.extname( file_name ).gsub( /^\./, '' ).downcase
  end

end

launcher = Launcher.new

end
我不确定这段代码应该运行什么,但我有多条错误消息

tinyapp.rb:8:in `initialize': wrong number of arguments (given 0, expected 1) (ArgumentError)
    from tinyapp.rb:30:in `new'
    from tinyapp.rb:30:in `<main>'
tinyapp.rb:8:in'initialize':参数数量错误(给定0,应为1)(ArgumentError)
来自tinyapp.rb:30:in'new'
来自tinyapp.rb:30:in`'

在这一行中,您正在实例化一个
启动器

launcher = Launcher.new
这将调用其上的
initialize
方法。该方法需要一个参数:

def initialize (app_map)
  @app_map = app_map
end
为了解决此错误,您需要为
app\u map
参数传入一个参数。我不知道这里到底应该是什么,但看起来是这样的:

launcher = Launcher.new(the_app_map)