调用方法时的Ruby语法

调用方法时的Ruby语法,ruby,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

在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]
语法是什么?

send(request\u method.to\u sym,path,options)
返回一个对象支持方法
[]
,例如一个
散列
,然后对其调用
[:body]

顺便说一句,如果您只需要动态方法调用,那么使用
send
会更好,不绕过可见性。如果不明显,您的问题同样适用于
response=my_method(路径,选项)[:body]