I would like to be able to do this in Ruby:
module A
@var = Object.new # could be any object
def f
puts @var.inspect
end
module_function :f
end
module B
def make_it(val)
# creates reference to val in this module under the same name as
# it appears in module A
end
module_function :make_it
end
So that this would make module B respond as does module A:
B.make_it(# a reference to @var in module A)
B.make_it(# a reference to f in module A)
This would allow B.f to act like A.f and B.f would return the 'inspect' of @var in module A or the 'inspect' of @var in B where it is a copy of that in A.
I have asked for references be made in B, but could live with copies as well.
Anyone know if this can be done? To have an example would be wonderful, but any assistance would be much appreciated. I have googled quite a bit without luck - perhaps I don't know how to phrase the search.