On 3/18/07, Christoph Rippel <chr_news / gmx.net> wrote: > > TRANS wrote: > ... > > BTW, someone asked for use cases. I recalled one yesterday. I used it > > for Infinity. Rather than have two singleton classes, one for positive > > Infinity and another for negative Infinity, I just have one multiton > > class with a negative/positive attribute. > > > > T. > > > I am not sure if your use case example is a good one. One can make the argument that +/- Infinity should be instances of distinct classes. I think whether my particular implementation for +/-Infinity is a good one is mostly irrelevant. My implementation works, and the Multiton proved valuable in it's construction. But if you feel it is relevant than there are at least three reasons I choose a single class over two singletons: 1) Asymmetric class names, eg. is it Infinity and NegativeInfinity or PositiveInfinity and NegativeInfinity? Neither of which I liked. 2) The code would be nearly identical between the two class, which begs for greater DRYness, especially if they become more complex --say if aleph is to be tracked. And 3) Neither Integer or Float have separate classes base on positive and negative, which is what Infinity mostly correlates too. > Let me also make some remarks about your implementation. The biggest problem is that it doesn't support marshalling (which pretty much boils down to remembering the initializing argument). That would be a good thing to fix. Thanks, I do that. > Also the implementation doesn't preserve the arity i.e. > > class A > def initialize(a,b) > end > include Multiton > > p arity(:new) # => 2 but > p arity(:instance) # => -1 > end > > This is probably just a minor but a "robust implementation" should support this, i.e. I would expect that > arity(:new) == arity(:instance) # => would return true > for any "Multiton" class. Which reminds me, it would be nice of Method could return a representation of a methods signature. I've run into this need elsewhere too. > Last but not least the use of Thread.critical is not supported in the main branch anymore - that is - you should use Mutex#synchronize. Oh, okay. I'll get that fixed too. Thanks for this. T.