instance method
clone
Ruby on Rails edge
Since v4.0.13Identical 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
user.name # => "Bob"
new_user.name = "Joe"
user.name # => "Joe"
user.object_id == new_user.object_id # => false
user.name.object_id == new_user.name.object_id # => true
user.name.object_id == user.dup.name.object_id # => false
Source
# File activerecord/lib/active_record/core.rb, line 541
Defined in activerecord/lib/active_record/core.rb line 541
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveRecord::Core