Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 谁能解释一下这个“ruby”的片段吗?_Ruby On Rails_Ruby_Http - Fatal编程技术网

Ruby on rails 谁能解释一下这个“ruby”的片段吗?

Ruby on rails 谁能解释一下这个“ruby”的片段吗?,ruby-on-rails,ruby,http,Ruby On Rails,Ruby,Http,有人能解释一下ruby的这段代码吗 def request_phase service_url = append_params( callback_url, return_url ) [ 302, { 'Location' => login_url( service_url ), 'Content-Type' => 'text/plain' }, ["You are being red

有人能解释一下ruby的这段代码吗

def request_phase
     service_url = append_params( callback_url, return_url )
    [

      302,
      {
        'Location' => login_url( service_url ),
        'Content-Type' => 'text/plain'
      },
      ["You are being redirected to CAS for sign-in."]
    ]
  end

服务url被分配给append参数方法的输出

然后request_phase返回一个数组,其中包含3项内容:

  • 整数:302

  • 哈希:包含“位置”和“内容类型”键(包括服务url,由append参数确定)

  • 数组:包含一个元素“您正在被重定向…”


  • 它是一个返回数组的函数。(ruby返回最后一个表达式,除非在该表达式之前显式返回)