Ruby: map tags into a boolean condition to get a true/false result
- by cgyDeveloper
I have an array of tags per item like so:
item1 = ['new', 'expensive']
item2 = ['expensive', 'lame']
I also have a boolean expression as a string based on possible tags:
buy_it = "(new || expensive) && !lame"
How can I determine if an item matches the buying criteria based on the tags associated with it? My original thought was to do a gsub on all words in buy_it to become 'true' or 'false' based on them existing in the itemx tags array and then exec the resulting string to get a boolean result.
But since the Ruby community is usually more creative than me, is there a better solution?