RUBY:找不到文件和命令的意外结束?

问题描述 投票:0回答:2

我开始学习Ruby,当我在终端上运行代码时遇到了一些问题。它说 :

desktop/RUBY/boucles.rb: line 1: voyages: command not found
desktop/RUBY/boucles.rb: line 14: syntax error: unexpected end of file.

我的ID是崇高的文字。

我怎么解决这个问题?

voyages = [
  { ville: "Paris", duree: 10 },
  { ville: "New York", duree: 5 },
  { ville: "Berlin", duree: 2 },
  { ville: "Montreal", duree: 15 }
]

voyages.each do |voyage|
  if voyage[:duree] <= 5
    puts "Voyage à #{voyage[:ville]} de #{voyage[:duree]} jours"
  end
end
ruby macos
2个回答
1
投票

这些错误看起来可能来自你的shell,而不是来自Ruby!

你是如何运行这个脚本的?您应该在终端中运行ruby boucles.rb


2
投票

您的代码是正确的,没有任何语法错误。如果您在Sublime Text中进行编辑,则可能需要确保先保存文件。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.