The ongoing discussions about ActiveSupport in Hooks lead me to believe that ActiveSupport is not as popular as i thought it is.
Don’t get me wrong, I didn’t get misleaded by comments like
ActiveSupport sucks and monkey craps on too many classes
although some of this is true 😀 It has wonderful helper methods and there’s a lot of work done for you already, but ActiveSupport is simply too complex.
After I found out that
Class.class_inheritable_array fails when doing
with some undefined method exception (at least with 2.3.9), I finally decided to do it on my own.
The current implementation is simple.
You use it like
class Cat extend Hooks::InheritableAttribute inheritable_attr :lifes self.lifes = 
and in subclasses
class Garfield < Cat self.lifes << "second"
so it is like ActiveSupport’s
class_inheritable_array. Less code, of course.
Where to go?
Not sure if methods like that should be packaged in separate gems? Or in a more generic gem aggregating features?
I mean, it would end up in some big
PassiveLaziness gem and we’d have two mainlines of handy ruby feature libraries.
So where to put such code? How can we make it modular and easily useable without automatically monkey patching every second class, as ActiveSupport does?
Any thoughts welcome!
5 thoughts on “Hooks goes without ActiveSupport and still has inheritable attributes”
I see no problem with ActiveSupport 3. While prior versions really cluttered object space (although except for some cases, I don’t even see problem with that too), AS3 is modular and allows you to use only extensions you want.
I like the new version !
It really fits into the rest of your clear, straightforward code.
I’d suggest you let it stay that way for a while.
It’s a helpful peace of code and and as a developer I can clearly see what’s going on, without wasting hours to explore.
It works on 2.3.9 and 3.0.0 an the practical usage in applications will give you feedback for future directions.
It’s good the way it is now!
In a case like this, where you need but one small method for one particular purpose within your own code, just add the method directly — to Hooks::ClassMethods in this case. No need for a dependency or and extra module.
P.S. Your mail field is buggy.
I’m trying to use hooks with Mixins. My setup is something like:
class B < A
Unfortunately this does not work. Any hints??
@Peter: This won’t work as you have to delay the define_hook block until the module is included.