From: Igor Pirnovar Date: 2012-10-27T16:14:04+09:00 Subject: Re: Name/symbol/object type clash? What is happening here? Robert, you continue pretending that you proved my point of view wrong by always providing only half of the solution, because you simply can not satisfy both requirements simultaneously. Namely, I require that both 'initialize' method as well as the attribute accessor (i.e.: the setter) method work correctly in tandem when an expression rather than the simple assignment is required. This code of yours simply doesn't work when using Struct, (nor does it work when you try to reopen 'S' as class, as was initially argued at the beginning of this thread): S = Struct.new :a do def initialize(a); self.a = a + 5; end alias _a= a= def a=(n) self._a= n + 5; end end s = S.new(0) p s.a #=> 10 WRONG!!! s.a = 100 p s.a #=> 105 With the exception of 'to_s' method, you see here the equivalent of the above code snippet of yours, this time using only classes (which BTW works correctly): class A attr_accessor :num def initialize(n); @num=n; end def to_s; "#{self.class}: num=#@num"; end end class B < A def initialize(n); super; @num = n + 5; end def num=(n) @num = n + 5; end end a = A.new(0) p "After: a=A.new(0) ... #{a}" #=> ... A: num=0 a.num = 100 p "After: a.num=100 .... #{a}" #=> ... A: num=100 b = B.new(0) p "After: b=B.new(0) ... #{b}" #=> ... B: num=5 b.num = 100 p "After: b.num=100 .... #{b}" #=> ... B: num=105 Once again, Struct does not provide satisfactory solution to both above stated initialization requirements, because it does not obey Ruby's '@' instance variable semantics, and due to this now revealed Ruby grammar inconsistency introduced by Struct, exposes broken blundering like yours as you try to botch your way out of it, when Ruby compounds double execution of expressions used in class/Struct initialization process (see my comment in your code: #=> 10 WRONG!!!). Regards, igor -- Posted via http://www.ruby-forum.com/.