From: tamouse mailing lists Date: 2013-02-25T01:58:39+09:00 Subject: Re: Why class returning its own name when "include" statement? --bcaec554001ad00b3e04d67b5578 Content-Type: text/plain; charset=UTF-8 On Feb 23, 2013 2:21 AM, "Love U Ruby" wrote: > > @Stefano Yes you are right. The below code is proved that. > > ********************************************************* > module Show > def show_string > p "hi" > end > end > # => nil > class Foo > @x=12 > (include Show).object_id > end > # => 10681980 > class Too > @x=12 > (include Show).object_id.inspect > end > # => "10648020" > ********************************************************* > > Does that mean @x has been already initialized? or curious to know what > "10648020" contains into it? @x is set inside the class and will be set thus when Foo.new or Too.new is called. Each such object will have its own copy of @x. The number in quotes is the inspected object id of the included Show module instance. > -- > Posted via http://www.ruby-forum.com/. > --bcaec554001ad00b3e04d67b5578 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


On Feb 23, 2013 2:21 AM, "Love U Ruby" <lists@ruby-forum.com> wrote:
>
> @Stefano Yes you are right. The below code is proved that.
>
> *********************************************************
> =C2=A0module Show
> =C2=A0def show_string
> =C2=A0p "hi"
> =C2=A0end
> =C2=A0end
> # =3D> nil
> =C2=A0 class Foo
> =C2=A0 @x=3D12
> =C2=A0 (include Show).object_id
> =C2=A0 end
> # =3D> 10681980
> =C2=A0 class Too
> =C2=A0 @x=3D12
> =C2=A0 (include Show).object_id.inspect
> =C2=A0 end
> # =3D> "10648020"
> *********************************************************
>
> Does that mean @x has been already initialized? or curious to know wha= t
> "10648020" contains into it?

@x is set inside the class and will be set thus when Foo.new or Too.new = is called. Each such object will have its own copy of @x.

The number in quotes is the inspected object id of the included Show mod= ule instance.

> --
> Posted via http://www.ruby-foru= m.com/.
>

--bcaec554001ad00b3e04d67b5578--