我有这样的事情:
case method
when :get
HTTParty.get(configuration.endpoint)
when :post
HTTParty.post(configuration.endpoint)
when :put
HTTParty.put(configuration.endpoint)
end
怎么做?
HTTParty.{method}(configuration.endpoint)
答案 0 :(得分:0)
您可以使用public_send
ruby方法
HTTParty.public_send(method)
或带参数
HTTParty.public_send(method, arg1, arg2)
public_send方法here
的文档