daniels wrote: > I thought something like this was in facets... maybe it was one of those > other library collections... either way I can't find what I'm looking > for, so here's an implementation which probably screws up with some > corner cases. > > class Reference > instance_methods.each { |m| undef_method m unless /__.*__/ === m} > def initialize(&block) > @block = block > end > def method_missing(*args, &block) > @block.call.send(*args, &block) > end > end > > my_hash = {} > my_hash["one"] = "First" > my_hash["two"] = "Second" > my_hash["three"] = "Third" > my_hash["four"] = Reference.new{my_hash["one"]} > my_hash["five"] = Reference.new{my_hash["four"]} > > my_hash["one"] = "Modify" > p my_hash["four"] > => "Modify" > p my_hash["five"] > => "Modify" > > >> element of hash object can point to another element. But i >> need the link to the key and not a copy of the value. > This is ok... but i have a question. If i dump the hash into a YAML file, then when i load it, the reference is lost and there are only copies of the same values. How can I mantain that reference when I dump/load the YAML file? Thank so mach to all for the help. --Andrea -- Posted via http://www.ruby-forum.com/.