R
Robert Dober
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 ?
Cheers
Robert
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 ?
Cheers
Robert