Module: Sequent::Core::Helpers::Copyable
- Included in:
- BaseCommand, Event, ValueObject
- Defined in:
- lib/sequent/core/helpers/copyable.rb
Overview
Make a deep clone of an object that include AttributeSupport
person = Person.new(name: 'Ben').copy(name: 'Kim')
You typically do not need to include this module in your classes. If you extend from Sequent::Core::ValueObject, Sequent::Core::Event or Sequent::Core::BaseCommand you will get this functionality for free.
Instance Method Summary collapse
Instance Method Details
#copy(attrs = {}) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/sequent/core/helpers/copyable.rb', line 15 def copy(attrs = {}) the_copy = Marshal.load(Marshal.dump(self)) attrs.each do |name, value| the_copy.send("#{name}=", value) end the_copy end |