Object#dup do in Ruby?Object#dup creates a shallow copy of an object. It copies the object's instance variables but does not copy the object's singleton methods or frozen state.
Object#clone different from Object#dup?Object#clone also creates a shallow copy but copies the frozen state and singleton methods of the original object, unlike dup.
dup copy singleton methods of an object?No, dup does not copy singleton methods. Only clone copies singleton methods.
dup and clone?dup does not copy the frozen state; the new object is unfrozen. clone copies the frozen state, so if the original was frozen, the clone is frozen too.
dup and clone.Both dup and clone create shallow copies, meaning they copy the object itself but not the objects referenced by its instance variables. Changes to nested objects affect both copies.
clone copies singleton methods; dup does not.
clone preserves frozen state; dup does not.
dup and clone create?Both create shallow copies, copying only the object itself, not nested objects.
dup?dup does not copy singleton methods or frozen state.
dup on a frozen object, what is the frozen state of the new object?dup creates an unfrozen copy even if the original was frozen.
Object#dup and Object#clone in Ruby.dup or clone on an object.