> The "Programming Ruby" book indicates that there may be semantic
> differences between "dup" and "clone", particularly in descendent
> classes.  I'm not entirely sure why there would be a difference and
> exactly what that difference is.  Could someone elaborate?

Jim, 

I'd love to be able to give you definitive answer but I'm not. After some
quick source reading I have to say I'm more puzzled. Anyway the idea is
quite well stated at

  http://www.rubycentral.com/ref/ref_c_object.html#dup

and

  http://www.rubycentral.com/ref/ref_c_object.html#clone

So, the basic idea is that clone works like "memcpy", copying the whole
state in which the object was (including instance variables, taintedness and
other flags), while dup concentrates only to copy the "contents", or
payload, of the object.

Anyway, here's an example:

  # Couple of dup and clone differences

  a = []
  a.freeze
  b = a.clone
  c = a.dup
  p a.frozen?, b.frozen?, c.frozen?
    # => true, true, false

  class Ary < Array
    def foo
      @foo = "foo"
    end
    def inspect
      (@foo ? @foo : "") + " " + super
    end
  end

  a = Ary.new
  a.foo
  b = a.clone
  c = a.dup
  p a.inspect, b.inspect, c.inspect
    # => "foo []", "foo []", " []"

(I'm not sure Ary.dup (which is inherited from Array) should _not_ copy
instance variables. I'm not sure enough of the concepts, but it might be a
design flaw (or, in other words, a bug :)).

	- Aleksi