Da Pondelok 13 Februr 2006 00:23 eastcoastcoder / gmail.com napsal: > Ruby does not allow subclassing true and false, so, if these methods > return one of those, they can't return any additional info. But > sometimes the caller needs additional info, as in: > You can subclass TrueClass or FalseClass, it just wouldn't do you much good. > if !valid? logger.warn "Not valid: #{why not?}" > > What is the best way to handle this? I could have those methods set > @instance_variables, but this seems a little hackish, and could > introduce race conditions. > Have whatever method changes state in the context of the snippet you posted return a object describing the result of an operation, including both those predicates and the reason? Besides, the #valid? and #abort? methods would still be subject to the same race conditions as any other place you'd store a reason info, I think. Personally, I smell some design weirdness, but can't really blame it with this little context. David Vallner