Difference Between Clone and Dup in Ruby

The clone and dup methods in Ruby are very similar, the key difference is that dup allows you to duplicate the value, but it regards object metadata.

This can be very handy when you want to duplicate a value that was previously frozen. A cloned copy would maintain the frozen state and would prevent changes, whereas by passing dup to the object, you can work with the duplicated object however you see fit.