Rajinder Yadav wrote:
> Can someone explain what's going on when dup is called. What gets passes 
> to dup
> (i assume self) and why my code is wrong?

dup is a method of your existing object, and should return the new 
object instance.

class A
  attr_accessor :name
  def dup
    res = self.class.new
    res.name = name.dup
    res
  end
end

a1 = A.new
a1.name = "yoyoma"
a2 = a1.dup
a1.name.chop!
puts a2.name

There is a subtle distinction between 'dup' and 'clone' which I'll leave 
someone else to explain...
-- 
Posted via http://www.ruby-forum.com/.