From: Pete Higgins Date: 2012-01-21T07:56:33+09:00 Subject: Re: Getting an Object to Push or Register "Itself" With a Hash During Initialization --20cf3079ba5687c89a04b6fd971c Content-Type: text/plain; charset=ISO-8859-1 On Fri, Jan 20, 2012 at 2:43 PM, Frank Guerino 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) => # > hash => {1=>#} pete --20cf3079ba5687c89a04b6fd971c--