[#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:03831] Re: Order of overwriting

From: Aleksi Niemel<aleksi.niemela@...>
Date: 2000-07-05 14:48:46 UTC
List: ruby-talk #3831
>  Well, I'm probably wrong, but the declarations overwrite 
> each other in the
>  order they are written, i.e.
> 
>      Foo#foo        overwrite Zak#foo
>      Foo_update#foo overwrite Foo#foo
> 
>  'include module' include method in the super class.

I guess you're not wrong. This is what I expect too. But the interesting
point is this:

class Bar < Zak
	def foo
		super
	end
	include Foo
	include Foo_update
end

So first Bar gets Zak's methods. Then I expect 'def foo' to overwrite and
after that Foo.foo and Foo_update. So when Bar.foo is called, it be call to
Foo_update#foo (holding the last definition), which super calls Foo#foo,
which in turn calls Bar#foo and it finally calls Zak#foo.

The prints indicate that actually Bar.foo is a call to Bar#foo and then the
rest of the chain: Foo_update#foo, Foo#foo, Zak#foo. This means, that the
source is actually magically transformed into following, before the order of
the method overwriting is as in source.

class Bar < Zak
	include Foo
	include Foo_update
	def foo
		super
	end
end

	- Aleksi

In This Thread

Prev Next