vendredi 8 mai 2015

Ruby ArgumentError when actually providing correct arguments

Ruby complains i am not providing enough arguments to my script, which is:

    #!/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")

What i get back is:

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'

I dont get this, the arguments i provide are obviously 2

Aucun commentaire:

Enregistrer un commentaire