Given a map fromof items to their attributes:
OPTIONS = {
paper: %w[A4_paper countable universal],
pencil: %w[trackable universal trackable],
chalk: %w[stationery countable trackable A4_paper],
}.freeze
I need to return the items that have a particular attribute. For example, fetch_type_values('countable') should return ["paper", "chalk"].
Here's my working implementation:
def fetch_type_values(option)
OPTIONS.map { |key, value| key if value.include?(option.to_s) }.compact.map(&:to_s)
end
I feel that this is a bit difficult to read; any suggestions how IHow can I refactor/simplify it to make it more readable?