From: Trans Date: 2007-11-27T23:17:10+09:00 Subject: Re: Strange code or Zerotons instead of Singletons On Nov 27, 4:48 am, "Robert Dober" wrote: > Hi list > > I am kind of attached to strange code in that moment, it somehow shows > up on it's own, I needed a singleton class and of course I had to > reinvent the wheel. > Actually, singletons do not always make sense, sometimes zerotons will > do the trick, so I created my zeroton > > class << MyZero = Class::new( Whatever ) { > def a; 42 end > def new *args, &blk > self # or raise YourEyeBrows > end > > } > > and why not > > module Kernel > def zeroton superclass = Object, &blk > returning( Class::new( superclass ) ) { |klass| > class << klass; self end.module_eval &blk > class << klass > def new *args, &blk > self > end > end > } > end > end > > MyZero = zeroton( Whatever ) { > def a; 42 end > > } > > Any thoughts, insults (moderated though;) ? Why are you using a class as if it were an instance? What's wrong with: MyZero = Whatever.new def what.a; 42; end T.