[#3986] Re: Principle of least effort -- another Ruby virtue. — Andrew Hunt <andy@...>

> Principle of Least Effort.

14 messages 2000/07/14

[#4043] What are you using Ruby for? — Dave Thomas <Dave@...>

16 messages 2000/07/16

[#4139] Facilitating Ruby self-propagation with the rig-it autopolymorph application. — Conrad Schneiker <schneik@...>

Hi,

11 messages 2000/07/20

[ruby-talk:03950] Multiple single inheritance?

From: Aleksi Niemel<aleksi.niemela@...>
Date: 2000-07-12 13:20:04 UTC
List: ruby-talk #3950
When I was wrestling with module definitions and 'inclusions' I couldn't
come up with a reason why we don't have multiple single inheritance (and
thus quite close to problem free (?) multiple inheritance).

  class Foo
    def foo
      puts "foo"
    end
    def bar
      puts "there's no bar in foo"
    end  end

  class Bar
    def bar
      puts "bar"
    end
  end

  class FooBar < Foo, Bar
    def foobar
      puts "foobar"
    end
  end

It would work like:

  class FooBar
    include_class 'Foo'  # definitions, class variables, locals,
    include_class 'Bar'  # whatever should be imported
    ...
  end

The example would work as follows (with additional definition for BarFoo):

  class BarFoo < Bar, Foo
  end

  Foo.new.foo          # => "foo"
  Foo.new.bar          # => "there's no bar in foo"

  Bar.new.bar          # => "bar"

  FooBar.new.foobar    #=> "foobar"
  FooBar.new.foo       #=> "foo"     from Foo#foo
  FooBar.new.bar       #=> "bar"     from Bar#bar

  BarFoo.new.foo       #=> "foo"     from Foo#foo
  BarFoo.new.bar       #=> "there's no bar in foo"  
                       #             from Foo#bar

The implementation wouldn't (?) be hard thing to do. The model would be same
as with handling modules.

Dead idea?

	- Aleksi

In This Thread

Prev Next