From: Yossef Mendelssohn Date: 2012-10-25T14:33:07+09:00 Subject: Re: Name/symbol/object type clash? What is happening here? --90e6ba614c809efb2604ccdb890a Content-Type: text/plain; charset=ISO-8859-1 On Wed, Oct 24, 2012 at 9:21 PM, 7stud -- wrote: > Todd B. wrote in post #1080981: > > > > Okay, I see, thanks. > > > > Okay, you see what? That was one of the worst responses I've ever read > on this forum. It completely missed the big picture. Your example > shows that ruby is a completely screwed up somewhere. You can't have > two constants with the same name, so your class should have overwritten > the Struct. Ruby is not screwed up, at least not in the ways you say it is. The `class S` line isn't declaring a new class named S, it's reopening the class created by Struct.new. S = Struct.new(:num) class S def show_num; puts "Show:#{self.num}"; end end is like S = Struct.new(:num) do def show_num; puts "Show:#{self.num}"; end end or similar enough to class S < Struct.new(:num) def show_num; puts "Show:#{self.num}"; end end -- -yossef --90e6ba614c809efb2604ccdb890a Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On Wed, Oct 24, 2012 at 9:21 PM, 7stud -- <lists@ruby-forum.com>= wrote:
Todd B. wrote in post #1080981:
>
> Okay, I see, thanks.
>

Okay, you see what? =A0That was one of the worst responses I've ever re= ad
on this forum. =A0It completely missed the big picture. =A0Your example
shows that ruby is a completely screwed up somewhere. =A0You can't have=
two constants with the same name, so your class should have overwritten
the Struct.

Ruby is not screwed up, at leas= t not in the ways you say it is. The `class S` line isn't declaring a n= ew class named S, it's reopening the class created by Struct.new.

=A0 =A0 S =3D Struct.new(:num)
=A0 =A0 class = S
=A0 =A0 =A0=A0def show_n= um; puts "Show:#{self.num}"; end
=A0 =A0 end

is like

= =A0 =A0 S =3D Struct.new(:num) do
=A0 =A0 =A0=A0def show_num; puts "Show:#{self.num}"; end<= /span>
=A0 =A0 end

or similar enough to
<= div>
=A0 =A0 class S < Str= uct.new(:num)
=A0 =A0 =A0=A0