On Tue, Oct 15, 2002 at 06:51:31AM +0900, dblack / candle.superlink.net wrote:
>   (s = (S = Struct.new :thing) .new) .thing = 123
>   # (I was shooting for a palindrome :-)  Anyway....
> 
>   class S
>     alias :oldthing :thing
>     def thing
>       puts "Intercepted attribute get"
>       oldthing
>     end
>   end
> 
>   p s.thing
>               #  => Intercepted attribute get
>               #     123

A cleaner way to do this is to derive the class from an anonymous struct.

class S < Struct.new :thing
  def thing
    puts "Intercepted..."
    super()
  end
end

s = S.new
s.thing = 123
p s.thing
               #  => Intercepted...
               #     123



-- 
Alan Chen
Digikata LLC
http://digikata.com