On Fri, Jan 20, 2012 at 2:43 PM, Frank Guerino <frank.guerino / if4it.com>wrote:

> Hi,
>
> How do I tell an object to register "itself" with a hash that has been
> passed in during initialization?
>
> For example, I have:
>
> # START ---------------------------
> hashOfHomes = {}
>
> Class House
>  def initialize homeAddress, homeHash
>    @localHomeAddressString = homeAddress
>    HOW DO I PUSH "THIS" OBJECT (I.E> "SELF") ONTO THE HASH DURING THIS
> INITIALIZATION????
>  end
> end
>
> home = House.new( "123 Main Street", hashOfHomes)
> # END   ---------------------------
>
> I've read through multiple references on object creation and "self" but
> don't see anything that is a clear answer.
>
> Thanks, in advance, for any assistance you can offer!
>
> Frank
>
> --
> Posted via http://www.ruby-forum.com/.
>
>
Something like this will work:

>   hash = {}
 => {}
> class A
>   def initialize(n, hash)
>     hash.merge! n => self
>     end
>   end
 => nil
> A.new(1, hash)
 => #<A:0x007f90b3159d20>
> hash
 => {1=>#<A:0x007f90b3159d20>}

pete