Hacker News new | past | comments | ask | show | jobs | submit login

Actually, 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.




but 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




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: