Is there a hook method called whenever a new class is created i.e.
guaranteed called for every new instance of Class ?
Class#initialize does not work.
Thanks.
Is there a hook method called whenever a new class is created i.e.
guaranteed called for every new instance of Class ?
Class#initialize does not work.
Thanks.
itsme213 wrote:
Is there a hook method called whenever a new class is created i.e.
guaranteed called for every new instance of Class ?
You can try Object.inherited, but I'm not sure if it will get called when a class is created internally in C code.
Plus it can be overridden in subclasses so there is no 100% guarantee of it getting called.
Ah. Considering your suggestion I realized that I really wanted a hook for
just when my classes were created. So MyBase#inherited or MyMod#included are
good hooks.
Thanks!
p.s. the solution to my earlier question on clean-up for eval'ing named
class definitions in unit tests turned out to be
Module#remove_const
"Florian Gross" <flgr@ccan.de> wrote in message
news:2vf8hfF2li20bU1@uni-berlin.de...
itsme213 wrote:
> Is there a hook method called whenever a new class is created i.e.
> guaranteed called for every new instance of Class ?You can try Object.inherited, but I'm not sure if it will get called
when a class is created internally in C code.Plus it can be overridden in subclasses so there is no 100% guarantee of
it getting called.
Florian Gross wrote:
itsme213 wrote:
Is there a hook method called whenever a new class is created i.e.
guaranteed called for every new instance of Class ?You can try Object.inherited, but I'm not sure if it will get called when a class is created internally in C code.
Plus it can be overridden in subclasses so there is no 100% guarantee of it getting called.
.
What about just putting the initialization code in the class definition?
class Foo
def bar
...
end
...
# class init
do_something
do_something_else
end
- Jamis
--
Jamis Buck
jgb3@email.byu.edu
http://www.jamisbuck.org/jamis
"Jamis Buck" <jgb3@email.byu.edu> schrieb im Newsbeitrag
news:41927269.1020701@email.byu.edu...
Florian Gross wrote:
> itsme213 wrote:
>
>> Is there a hook method called whenever a new class is created i.e.
>> guaranteed called for every new instance of Class ?
>
>
> You can try Object.inherited, but I'm not sure if it will get called
> when a class is created internally in C code.
>
> Plus it can be overridden in subclasses so there is no 100% guarantee
of
> it getting called.
>
> .
>What about just putting the initialization code in the class definition?
class Foo
def bar
...
end
...
# class init
do_something
do_something_else
end
I think 213 wanted some automated mechanism, so you can't forget it when
you create a new class.
robert