There are a few ways to do this, and I’m surprised you haven’t had a few
answers yet! So… I’ll provide some pointers in code. You will need to
tidy
this up and structure it better, but it should at least demonstrate a
concept…

class Module

Why in Module and not Class? Because otherwise you couldn’t use it

within module definitions… only classes, whereas Module lets you

cover

both…

def attr_proxied_accessor(var)
define_method(var) do
# At this stage, we’re defining the “x” method…
10
end

define_method(:"#{var}=") do |v|
# At this stage, we're defining the "x=" method..
end

end
end

class Something
attr_proxied_accessor :x
end

puts Something.new.x

There’s still some way to go, such as actually calling your proxy
routines
and doing the “instance variable set/get”, but it should at least crack
the
biggest problem…? If you continue to get stuck, Googling around looking
for
full code to attr_accessor provides a few techniques.

Maybe you would like to have a look at my personal favorite of all
Ruby Q.zes(*) (well that is of course save my own - just kidding-
there are lots of close seconds BTW):http://rubyquiz.com/quiz67.html
I am quite sure that this should cover your needs.