From: James Edward Gray II Date: 2010-11-03T03:51:26+09:00 Subject: Re: the dark side of inherited methods On Nov 2, 2010, at 1:25 PM, Joel VanderWerf wrote: > On 11/02/2010 11:12 AM, James Edward Gray II wrote: >> A = Struct.new(:x, :y, :z) do >> def length >> Math.sqrt(x**2 + y**2 + z**2) >> end >> end > > How do you fix this? > > A = Struct.new :x, :y, :z do > def length > Math.sqrt(x**2 + y**2 + z**2) > end > > def x=(new_x) > raise ArgumentError if new_x > 100 > super > end > end > > a = A.new > a.x = 1 # NoMethodError Good question. It works to replace super with: self[:x] = new_x I realize that's not an ideal solution though. James Edward Gray II