参考net-ssh API,传递来自 yaml 的连接参数的“最佳”方式是什么?
错误:
thufir@dur:~/ruby$
thufir@dur:~/ruby$ ruby ssh.rb
{:host=>"localhost", :user=>"me", :port=>123, :password=>"mypassword"}
/home/thufir/.rvm/gems/ruby-2.0.0-p247/gems/net-ssh-2.6.8/lib/net/ssh.rb:165:in `start': wrong number of arguments (1 for 2..3) (ArgumentError)
from ssh.rb:14:in `<main>'
thufir@dur:~/ruby$
代码:
#!/usr/bin/env ruby
require 'rubygems'
require 'net/ssh'
require 'yaml'
require 'pry'
conn = YAML.load_file('conn.yml')
params = {:host => conn['host'], :user => conn['user'],
:port => conn['port'],:password => conn['password']}
puts params
Net::SSH.start(params) do |ssh|
puts 'hi'
end
yaml:
user: me
password: mypassword
port: 123
host: localhost
是否可以只传递一个整体对象?或者,您是否必须将其分解为主机、用户等。人。?