How to design a class which has a list of boolean variables?
I have a Ruby class called Category which has various boolean values like
So I will associate this Category class with some other class to define its category, basically the issue is all variables within this class are just booleans. Is it best to use 4 different variables in Ruby class or use an integer and encode the booleans into it?
But if I encode the code becomes not so flexible incase I want to add another variable to this case, so what's the best way to do this?
Wouldn't it be better if you represent the categories with an array of symbols like categories = [:sport,:food] ? Probably you're checking something like if (sport) in your code, which could be replaced by if (categories.include? :sport) (which in my opinion is even more meaningful). This way, you would have an array with the "true values" instead of having lots of boolean variables, which is way more extensible and maintainable and seems to achieve what you need.
Anyway, I'm lacking more information about your classes, maybe if you can provide more information about your classes I could give you better advice.