Notes:
I am afraid I willI'd propose a very boring solution: don't use meta-programming. I mean, why add methods and more methods, polluting the class, when you can add just one usingmethod and use symbols for the days? Add validations if you're worried about invalid values for days.
The usual trick of using powers of two as a mask is that, a trick, very handy in low-level languages (C, assembler, ...). In a higher-level language you strive for writing code as declarative as possible, with data structures like lists, hashes, trees, or sets, not masks of powers of 2 :-) Here I'd use a set.
I prefer functional solutions even with OOP, just return new instances instead of modifying the existing ones. Referential transparency, idempotence, all the goodies follow.
I'd write (orientative, you get the idea):
class WeekSauce
DAY_NAMES = [:sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday]
def initialize(days)
@days = days.to_set & DAY_NAMES
end
def has_day?(name)
@days.include?(name)
end
def add_days(names)
WeekSauce.new(@days.union(names))
end
end