在命令行方法执行ruby文件时,需要从命令行中传入参数,可以使用全局变量:ARGV

如有ruby 文件test.rb,内容如下:

1 def hello(a)
2   puts a
3 end
4 
5 hello(ARGV)

这时在命令行中输入:

ruby -w test.rb "hello"

程序输出为:

hello

 

相关文章:

  • 2021-07-25
  • 2021-11-20
  • 2021-05-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-27
  • 2021-06-23
猜你喜欢
  • 2022-12-23
  • 2021-08-26
  • 2022-02-16
  • 2022-12-23
相关资源
相似解决方案