Henrik Ronellenfitsch ha scritto:

> 
> If you write these methods yourself instead of using the 
> attr_-construct, you can do whatever you want in the methods and it 
> still looks the same to everyone who uses your class.
> 

I /think/ he knew this and was looking for a way to define a bunch of 
attributes with a common behaviour, say,

class Foo
  attr_with_logging :foo
end
Foo.new.foo=10 #Foo::Logger.log "changed foo in instance 123456"

This is not hard to do, and has imvho, little usage so I don't think it 
would be needed in core ruby. But this may be an example of "I Don't 
Have It So I Don't Need It".

Anyway, you could take a look at how mauricio fernandez implemented 
simple AOP in ~20 lines of ruby here:
http://www.thekode.net/ruby/techniques/CapturingMethods.html

or just use something like:

##warning dumb implementation ahead


class Module
     def attr_with_pre_hook(sym,&blk) #just handles accessors
         define_method(sym) do
           tmp=instance_variable_get "@"+sym.to_s
           blk.call(tmp)
           tmp
         end
     end
end

class Foo
  attr_writer :bar
  attr_with_pre_hook(:bar) {|b| puts b }
end

f=Foo.new
f.bar=20
p f.bar