An API is expected to return following result.
{
"age_range": {
"max": 30,
"min": 20
}
}
An instance which implemented with MyApiClient returns that result as Sawyer::Resource.
result = ApiClient.request
result[:max] # => 30
However, if the API returns following result, above execution will unexpected result.
{
"age_range": {
"min": 20
}
}
result = ApiClient.request
result[:max] # => [:min, 20]
The cause is into the Sawyer::Resouce implementation. Sawyer::Resouce#[] calls #method_missing and searches the key from inner fields.
Ordinarily it will return nil if does not find the key.
However, :max is Enumerable module instance so it will happen that calls Enumerable#max method.