Home Ruby Ruby脚本中的几个基本变量$0,argv
Post
Cancel

Ruby Ruby脚本中的几个基本变量$0,argv

$0:  当前文件的名称。

ARGV: 运行当前rb文件时,添加的 参数。

例如:

# test.rb
puts "=hi"
puts ARGV               
puts "== $0 : #{$0}"    

运行方式:  ruby test.rb  'argv1'

=hi

argv1

== $0 : test.rb

This post is licensed under CC BY 4.0 by the author.