3 ms·
Dynamic inheritance is not unthinkable, I've used it in my languages before (or see research languages like Cecil). Of course, you can do this easily in dynamic
by seanmcdirmid 14y ago
Dynamic inheritance is not unthinkable, I've used it in my languages before (or see research languages like Cecil). Of course, you can do this easily in dynamic languages like ruby.
- jrochkind1 14y agoActually, can you really do dynamic inheritance in ruby? I don't _think_ so. There are ways to apply inheritance dynamically at runtime of course (including with module mix-ins, which are basically just inheritance even though ruby pretends it isn't), but I don't think you can _undo_ inheritance at runtime. You can easily simulate dynamic inheritance in ruby.... with composition, using delegate-like patterns.
- draegtun 14y agobut I don't think you can _undo_ inheritance at runtime I'd be surprised if you couldn't do it in Ruby. You certainly can do it in Perl because it uses a package (class) variable called @ISA for it's inheritance lookup. And because package variables are dynamically scoped you can do this: { # remove everything except father from inheritance local @Some::Class:ISA = $Some::Class::ISA[-1]; $some_object->foo; # finds father foo() only } $some_object->foo; # runs first foo() found in inheritance