为作为参数传递的每个数组项运行Ruby块

时间:2017-10-30 17:13:53

标签: ruby

挣扎着这个简单的任务。不是Ruby的专家:

  def self.send_mass_sms(*number, message)
    *number.each do |n|
      @client.messages.create(
        from: ENV['TWILIO_PHONE_NUMBER'],
        to: "+370#{n}",
        body: "#{message}"
      )
    end 
  end

号码为string[] - [" 657765"," 765475"]

错误:

  

语法错误,意外' \ n',期待&amp ;.或::或' ['或者'。'

1 个答案:

答案 0 :(得分:3)

尝试删除*符号

def self.send_mass_sms(*number, message)
  number.each do |n|
    @client.messages.create(
      from: ENV['TWILIO_PHONE_NUMBER'],
      to: "+370#{n}",
      body: "#{message}"
    )
  end
end