From: Gennady Bystritsky Date: 2009-01-13T16:35:39+09:00 Subject: Re: 99.respond_to? :dup ==> true 2 points here (and sorry for the top posting -- my web mail client does not quote properly): 1. It may be the case that if an object is not dup()-able, you better not quietly continue with an original object as modifying it may cause undesired side effects. In this case, an exception from calling dup(), either NoMethodError or TypeError (can't dup Fixnum), is a valid reason to report a datatype error. 2. Instead of dup()-ing, you may consider using a proxy class that will delegate to the original object, yet keeping track of all modifications. It will work even for data types that do not support dup(). Best, Gennady. ________________________________________ From: sentinel.2001@gmx.com [sentinel.2001@gmx.com] Sent: Monday, January 12, 2009 23:06 To: ruby-talk ML Subject: 99.respond_to? :dup ==> true I have values of various datatypes coming into this method and the method does a dup, since it modifies the values and obviously does not want to change the original. However, Fixnum's do respond to :dup but give an error when called. First off, can someone explain this to me. Second, i have worked around it with a "rescue" clause. In future, should I avoid using "respond_to?" since it could cause errors. Should I always use rescue. I now have: value = value.dup rescue value -- Posted via http://www.ruby-forum.com/.