如何将另一个方法的结果添加到数组中

时间:2017-04-20 23:04:18

标签: arrays ruby ruby-on-rails-4

我有以下方法,我正在尝试将customer_status.status添加到结果数组,但收到错误undefined method <<

def self.latest_customer_details(user_id)
  latest = latest_within_last_year(user_id)
  return nil unless latest.present?
  customer_status = customer_status(user_id)
  result = Customer.new('customer_info', latest.customer_info, latest.status, latest.purchase_date)
  result << customer_status.status
end

我该如何解决?

1 个答案:

答案 0 :(得分:-1)

由于这一行:

customer_status = customer_status(user_id)

变量customer_status成为customer_status(user_id)的返回值或最后一行。因此,当您尝试调用customer_status.status时,它不知道如何调用它,因为customer_status方法已被覆盖。