From: Robert Klemme Date: 2010-11-03T17:22:12+09:00 Subject: Re: the dark side of inherited methods On Tue, Nov 2, 2010 at 7:51 PM, James Edward Gray II wrote: > 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. ... as is wasting a class because one wants to spare the typing IMHO. :-) Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/