module ISO3166::CountryClassMethods
def collect_countries_with(query_val, query_method = :alpha2, result_method = :itself)
-
(Array)
- An array of countries matching the provided query, or the result of applying `result_method` to the array of `Country` objects
Parameters:
-
result_method
(Symbol
) -- An optional method of `Country` to apply to the result set. -
query_method
(Symbol
) -- An optional query method, defaults to Country#alpha2 -
query_val
(String
) -- A value to query using `query_method`
def collect_countries_with(query_val, query_method = :alpha2, result_method = :itself) return nil unless [query_method, result_method].map { |e| method_defined? e }.all? all.select { |country| country.send(query_method).include? query_val } .map { |country| country.send(result_method) } end