Point an element in Hash Object

Oh... and your actual problem is that the HashReference object isn't
actually getting the to_yaml call - it's passing that through to the
wrapped object, which writes itself out in full. You'll need to add
to_yaml (or is it some other method? Check the YAML docs) to the methods
that aren't removed.

(instance_methods - ["__send__", "__id__","to_yaml"]).each {|m|
undef_method m}

···

-----Original Message-----
From: Daniel Sheppard
Sent: Tuesday, 20 December 2005 9:10 AM
To: ruby-talk ML
Subject: Re: Point an element in Hash Object

> 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?

You can't serialize procs (well... you can, sort of, but it's best not
to think about it).

So, you'll need to make a more specific Reference class:

class HashReference
  instance_methods.each {|m| undef_method m unless /__.*__/ === m}
  def initialize(hash, key)
    @hash = hash
    @key = key
  end
  def method_missing(*args, &block)
    @hash[@key].send(*args, &block)
  end
end

#####################################################################################
This email has been scanned by MailMarshal, an email content filter.
#####################################################################################
#####################################################################################
This e-mail message has been scanned for Viruses and Content and cleared
by NetIQ MailMarshal
#####################################################################################