Ruby on Rails latest stable (v6.1.7.7) - 0 notes - Class: Core
clone public

Identical to Ruby’s clone method. This is a “shallow” copy. Be warned that your attributes are not copied. That means that modifying attributes of the clone will modify the original, since they will both point to the same attributes hash. If you need a copy of your attributes hash, please use the #dup method.

user = User.first
new_user = user.clone               # => "Bob" = "Joe"               # => "Joe"

user.object_id == new_user.object_id            # => false ==  # => true ==  # => false
Show source
Register or log in to add new notes.