通过命令行将变量传递给 Ruby 脚本 [英] Pass variables to Ruby script via command line

查看:37
本文介绍了通过命令行将变量传递给 Ruby 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 Windows 上安装了 RubyInstaller 并且我正在运行 IMAP Sync 但我需要使用它同步数百个帐户.如果我可以通过命令行将这些变量传递给它,我就可以更好地自动化整个过程.

I've installed RubyInstaller on Windows and I'm running IMAP Sync but I need to use it to sync hundreds of accounts. If I could pass these variables to it via command line I could automate the whole process better.

# Source server connection info.
SOURCE_NAME = 'username@example.com'
SOURCE_HOST = 'mail.example.com'
SOURCE_PORT = 143
SOURCE_SSL  = false
SOURCE_USER = 'username'
SOURCE_PASS = 'password'

# Destination server connection info.
DEST_NAME = 'username@gmail.com'
DEST_HOST = 'imap.gmail.com'
DEST_PORT = 993
DEST_SSL  = true
DEST_USER = 'username@gmail.com'
DEST_PASS = 'password'

推荐答案

是这样的:

ARGV.each do|a|
  puts "Argument: #{a}"
end

然后

$ ./test.rb "test1 test2"

v1 = ARGV[0]
v2 = ARGV[1]
puts v1       #prints test1
puts v2       #prints test2

这篇关于通过命令行将变量传递给 Ruby 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆