From: Paul Brannan Date: 2002-02-23T04:24:26+09:00 Subject: Re: dispatching and class references On Sat, Feb 23, 2002 at 04:19:19AM +0900, Mark Probert wrote: > Thank you for everyone for helping me with my dispatch > query the other day. Now fro part 2 :-) > > It seems that ruby returns object values by reference. > Is there any way to return the value? I would like the > pattern, stored in Sym::val to be treated as a template > and retain its value ('xxx') over each dispatch call. Returning by value is almost the same as returning a reference to a copy. To make a smallow copy: obj.dup To make a deep copy: Marshal::load(Marshall::dump(obj)) Returning copies will have a performance impact. If you want to return a reference but still not allow the user to change the returned object, you can return a frozen object. Paul