Sha256: 6cc7c72968a3f5fa781f347c10251c2a8e25c8555ee823369794b4e44185f820
Contents?: true
Size: 618 Bytes
Versions: 5
Compression:
Stored size: 618 Bytes
Contents
# frozen_string_literal: true require 'deep_merge/rails_compat' require 'dry/struct' require 'modern/types' module Modern class Struct < Dry::Struct module Copy # This implementation is necessary because the "fast" way (hash, merge, recreate) # WILL EAT YOUR TYPE DATA. This is the only way I can find to copy-but-change an # object that doesn't. # # Computers are bad. def copy(fields = {}) self.class[self.class.attribute_names.map { |n| [n, self[n]] }.to_h.merge(fields)] end end constructor_type :strict_with_defaults include Copy end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
modern-0.4.6 | lib/modern/struct.rb |
modern-0.4.5 | lib/modern/struct.rb |
modern-0.4.4 | lib/modern/struct.rb |
modern-0.4.3 | lib/modern/struct.rb |
modern-0.4.2 | lib/modern/struct.rb |