调用方法时的Ruby语法

时间:2013-11-19 03:01:17

标签: ruby

在GitHub上找到这个源代码:

def objects_from_response(klass, request_method, path, options={})
  response = send(request_method.to_sym, path, options)[:body]
  objects_from_array(klass, response)
end

对于这一特定行:

response = send(request_method.to_sym, path, options)[:body]

方法之后的[:body]语法是什么?

1 个答案:

答案 0 :(得分:3)

send(request_method.to_sym, path, options)返回对象支持方法[],例如Hash,然后在其上调用[:body]