RubyFlow The Ruby and Rails community linklog

The differences between dup and clone in Ruby

I just wrote a quick explanation with examples of the differences between copying and cloning a Ruby object. I’ve also added a quick explanation of shallow object copying.

Comments

AWESOME. I had no idea clone copied singleton class and dup didn’t. That matters. If you submitted a doc patch to MRI to actually document this in Object#dup and Object#clone, that’d be super kind!

Post a comment

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in