MonkeeSage
11/27/2007 2:32:00 PM
On Nov 27, 8:17 am, Trans <transf...@gmail.com> wrote:
> On Nov 27, 4:48 am, "Robert Dober" <robert.do...@gmail.com> 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.
^ That was my thought too, but since he mentioned singleton, I thought
maybe he wanted a class object he could instantiate multiple times and
all of them would have whatever was in the block...like Whatever with
an anonymous mixin.
Regards,
Jordan