我有以下课程:
module APIWrapper
include HTTParty
BASE_URI = 'https://example.com/Api'
def self.const_missing(const_name)
anon_class = Class.new do
def self.method_missing method_name, *params
params = {
'Target' => const_name.to_s,
'Method' => method_name.to_s,
}
APIWrapper.call_get params
end
end
end
def self.call_get(params)
get(APIWrapper::BASE_URI, {:query => params})
end
def self.call_post(params)
post(APIWrapper::BASE_URI, params)
end
end
我希望能够像这样调用我的包装器:
APIWrapper::User::getAll
我收到堆栈级别太深的错误:
1) Error:
test_User_getAll(APITest):
SystemStackError: stack level too deep
api_test.rb:16
我究竟做错了什么?