I am trying to refactor my code (before it was a bunch of if/else-if statements) using some Ruby magic. However, when I try to use code blocks as my value in a hash, I get the following error:
syntax error, unexpected '}', expecting tASSOC :restaurant => { Cuisine.all },
This same error repeats for the next line and the line after (:hotel
and :attraction
).
What am I doing incorrectly here?
def moderation_categories(klass)
klass_map = {
:restaurant => { Cuisine.all },
:hotel => { Category.where(place_type: "Hotel") },
:attraction => { Category.where(place_type: "Attraction") }
}
list = []
klass_map[klass.to_sym].call.each { |c| list << c.name }
list.sort
end