On Oct 25, 2012, at 13:22 , Igor Pirnovar <lists / ruby-forum.com> wrote:

> Yossef Mendelssohn wrote in post #1081211:
>=20
>> Just because something doesn't work the way you insist it must =
doesn't
>> mean it's broken.

exactly.

> If you claim that using accessors and '@' variables when reopening
> Struct classes with class idiom isn't broken, that's fine, but my last
> example I gave, clearly indicates differently!

Clearly? No. Your example is wrong, as shown by a simple -w:

9999 % ruby19 -w
 S =3D Struct.new(:num)
 class S
   attr_accessor :num
   def initialize(n); @num=3Dn+5; end
   def num=3D(n); @num =3D n+5; end
 end
-:3: warning: method redefined; discarding old num
-:3: warning: method redefined; discarding old num=3D
-:5: warning: method redefined; discarding old num=3D

Reimplementing the accessors breaks the explicit contract of Struct. =
There's no point in doing so at all and your example is simply wrong. =
Breaking the contract of initialize is also wrong, you're not even =
calling super.

> If you do not need it to
> be consistent in those simple circumstances you use Struct idiom, that

Struct is not an idiom. It is a class. Its internals are an =
implementation detail. =46rom the very first line of the rdoc on the =
class: "A Struct is a convenient way to bundle a number of attributes =
together, USING ACCESSOR METHODS" (emphasis mine).

> by no means discredits a more elaborate use, which clearly is broken,
> redundant and inconsistent, as I have shown in my previous sample code
> snippet, where you need to annul the Struct by the {{ attr_accessor =
:num
> }} line when you reopen the 'S' class, in order to be able to define
> more elaborate custom initialization accessor methods.

"Be able to"? You're blowing this WAY out of proportion:

% ruby19 -w
S =3D Struct.new(:num)
class S
  def initialize n
    super
    self.num =3D n + 5
  end
end
p S.new(10).num # =3D> 15

Looks like it is more than able to.

> Let's not waste any more time on this issue. I think we all can =
tolerate
> this apparent glitch. At the same time reiterating that there should =
be
> as few exceptions as possible in the language grammar and its use
> certainly is not an out of line proposition.

This has nothing to do with grammar. Again, Struct is a class, not =
grammar.