Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从命令行运行Ruby脚本?_Ruby - Fatal编程技术网

如何从命令行运行Ruby脚本?

如何从命令行运行Ruby脚本?,ruby,Ruby,我有一个文件,可以使用以下命令行运行该文件: ruby filename.rb 哪些产出: 12345 另一个脚本包含: def hi() puts "hello" end 从命令行运行时不返回任何内容 如何从命令行运行此命令?尝试将其放入filename.rb中: 然后在命令行中运行代码:with ruby filename.rbAdd将hiJohn放在方法的底部: def hi(name) puts "hello" end puts hi("John") 约翰就是你想要的名字

我有一个文件,可以使用以下命令行运行该文件:

ruby filename.rb
哪些产出:

12345
另一个脚本包含:

def hi() 
puts "hello"
end
从命令行运行时不返回任何内容

如何从命令行运行此命令?

尝试将其放入filename.rb中:

然后在命令行中运行代码:with ruby filename.rb

Add将hiJohn放在方法的底部:

def hi(name)
  puts "hello"
end

puts hi("John")
约翰就是你想要的名字


然后像往常一样运行它,ruby yourfilename.rb

这是教程中介绍的一个非常基本的问题。你在哪里搜索过,为什么这些信息没有帮助?请阅读并@theTinMan-是的,因为我是初学者,并通过教程进行搜索。但是没有发现这个具体的问题。也许使用ruby快速搜索internet调用一个方法?@theTinMan-我正在编写本教程-当他们浏览示例并更改代码时,很难在irb控制台上进行管理。@kasper_341如果你在irb中,你需要使用exit退出它,然后运行我回答中的代码。确保您在命令行的正确目录中。在运行脚本之前是否保存了文件?只是想覆盖所有的基地。谢谢你的帮助。它现在起作用了。可能是打字错误吗
def hi(name)
  puts "hello"
end

puts hi("John")