Each Ruby class is responsible for implementing its own clone
and dup
behaviour. Sometimes this manifests as a really weak implementation that doesn't do it correctly.
Queue doesn't seem to implement clone
, it's not in the documentation, so it's leaning on the Object#clone
method that is apparently insufficient for this task. All that does is copy instance variables into a new container, but it doesn't modify the instance variables themselves. Whatever internals Queue uses are unaffected.
So in short, some things can be cloned easily, others are much more difficult.
If you really need to clone a Queue, maybe you can serialize it and deserialize it, though that usually incurs a massive performance penalty.
Queue
doesn't seem to support Enumerable
so that limits your options for extracting and copying data. I'd guess that the performance concerns of Queue were such that convenience methods like that were omitted.