From: Caleb Clausen Date: 2010-07-08T07:32:51+09:00 Subject: [ruby-core:31115] Re: Why is the inherited callback invoked at different times for static vs. dynamic subclasses? --00235452eebcf6ee68048ad3bf5e Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Tue, Jul 6, 2010 at 1:43 AM, Jacob Lauem=F8ller < jacob.lauemoeller@iteray.com> wrote: > Hi all, > > Please consider this example: > > > class A > def self.inherited(subclass) > puts "A was inherited by #{subclass}" > end > end > > class B < A > puts "Definition of #{self}" > end > > C =3D Class.new(A) do > puts "Definition of #{self}" > end > > > When run, the output is > > A was inherited by B > Definition of B > Definition of # > A was inherited by # > > So, the inherited callback was called *before* the class body in the > "static" subclass B, but *after* the code in the block passed to Class.ne= w > for the dynamic subclass C. Is this a bug? > > My question is: why is this so? Shouldn't the two ways of creating > subclasses be equivalent? > This behavior is also unexpected to me. Perhaps it's a bug? If not, is ther= e a reason for these semantics? --00235452eebcf6ee68048ad3bf5e Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

On Tue, Jul 6, 2010 at 1:43 AM, Jacob La= uem=F8ller <jacob.lauemoeller@iteray.com> wrote:
Hi all,

Please consider this example:


class A
=A0def self.inherited(subclass)
=A0 =A0puts "A was inherited by #{subclass}"
=A0end
end

class B < A
=A0puts "Definition of #{self}"
end

C =3D Class.new(A) do
=A0puts "Definition of #{self}"
end


When run, the output is

A was inherited by B
Definition of B
Definition of #<Class:0x100124e80>
A was inherited by #<Class:0x100124e80>

So, the inherited callback was called *before* the class body in the "= static" subclass B, but *after* the code in the block passed to Class.= new for the dynamic subclass C. Is this a bug?

My question is: why is this so? Shouldn't the two ways of creating subc= lasses be equivalent?

This behavior is also unexpe= cted to me. Perhaps it's a bug? If not, is there a reason for these se= mantics?

--00235452eebcf6ee68048ad3bf5e--