新手问题 求问此处是变量还是方法调用

scuwolf · October 23, 2013 · Last by scuwolf replied at October 23, 2013 · 1618 hits

class Plugin

  def needs(*libraries)
    if libraries.empty?
      @needs ||= [ ]
    else
      needs.push(*libraries.flatten) # 这里needs是变量还是方法调用? 上下文中并没有找到有needs这个数组的初始化操作啊
    end
  end

end

明显方法调用,递归

#1 楼 @kikyous

哦,悟了。空参数的方法调用,初始化 @needs 这个实例变量为 [], 然后 push

擦,这写法好诡异...

You need to Sign in before reply, if you don't have an account, please Sign up first.