T
Trans
I would like to see someone else do this. I've simplified the issue to
a small exercise. Given:
module MyEnhancement
def attr_accessor(*a)
put "doing something special with #{a.join(' ')}"
super(*a)
end
end
This module can be used in any class or module simply by using
#extend.
class SomeClass
extend MyEnhancement
end
Great. However, I also want the end-user of this library to be able
effect all classes and modules with a single extend (or include) as
well, if they so choose. Eg.
class Module
include MyEnhancement
end
It would also be nice if the module's methods can be made to work from
the toplevel (main):
extend MyEnhancement
Of course, these last two pieces of code do not work.
In attempting to implement this, I have found myself resorting to
unDRY, ugly, hacky code, that always seems to have a bug in it
somewhere. It's infuriating. This is not how programming Ruby is
supposed to be!
a small exercise. Given:
module MyEnhancement
def attr_accessor(*a)
put "doing something special with #{a.join(' ')}"
super(*a)
end
end
This module can be used in any class or module simply by using
#extend.
class SomeClass
extend MyEnhancement
end
Great. However, I also want the end-user of this library to be able
effect all classes and modules with a single extend (or include) as
well, if they so choose. Eg.
class Module
include MyEnhancement
end
It would also be nice if the module's methods can be made to work from
the toplevel (main):
extend MyEnhancement
Of course, these last two pieces of code do not work.
In attempting to implement this, I have found myself resorting to
unDRY, ugly, hacky code, that always seems to have a bug in it
somewhere. It's infuriating. This is not how programming Ruby is
supposed to be!