gpt4 book ai didi

实际提供正确参数时的 Ruby ArgumentError

转载 作者:数据小太阳 更新时间:2023-10-29 07:55:35 25 4
gpt4 key购买 nike

Ruby 提示我没有为我的脚本提供足够的参数,即:

    #!/usr/bin/ruby
require 'mail'

def send(file,recipients_csv)
recipients=recipients_csv.split(",")
recipients.each do |recipient|
Mail.defaults do
delivery_method :smtp,{ :address => 'localhost', :port => 25,:openssl_verify_mode => OpenSSL::SSL::VERIFY_NONE}
end
mail = Mail.new do
from 'noreply@mydomain.com'
to "#{recipient}"
subject "test"
body "test"
add_file :filename => "a_testfile.tsv", :content => File.read(file.path)
end
mail.deliver!
end
end

testfile=File.new("newfile.tsv","w")
send(testfile,"name@mydomain.com")

我得到的是:

Mailer.rb:4:in `send': wrong number of arguments (1 for 2) (ArgumentError)
from /usr/lib64/ruby/gems/1.9.1/gems/treetop-1.4.15/lib/treetop/runtime/compiled_parser.rb:18:in `parse'
from /usr/lib64/ruby/gems/1.9.1/gems/mail-2.5.4/lib/mail/elements/address_list.rb:26:in `initialize'
from /usr/lib64/ruby/gems/1.9.1/gems/mail-2.5.4/lib/mail/fields/common/common_address.rb:9:in `new'

我不明白,我提供的参数显然是 2

最佳答案

这可能与 Ruby 基础 send 方法冲突。尝试将 send 重命名为 send_mail(或其他名称),以避免覆盖 send 方法

关于实际提供正确参数时的 Ruby ArgumentError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30126124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com