module Wardrobe::Plugins::ImmutableInstanceMethods

Constants

IMMUTABLE_CORE_CLASSES

Public Instance Methods

_mutating?() click to toggle source
# File lib/wardrobe/plugins/immutable.rb, line 12
def _mutating?
  instance_variable_defined?(:@_mutating) && @_mutating
end
deep_freeze() click to toggle source
# File lib/wardrobe/plugins/immutable.rb, line 41
def deep_freeze
  each { |_k, v| v.deep_freeze }
  freeze
end
mutate(**args, &blk) click to toggle source
# File lib/wardrobe/plugins/immutable.rb, line 16
def mutate(**args, &blk)
  dup.instance_exec do
    instance_variable_set(:@_mutating, true)
    blk.call(self) if block_given?
    args.each do |name, _value|
      if (atr = _attribute_store[name])
        _attribute_init(atr, args, name)
      end
    end
    remove_instance_variable(:@_mutating)
    deep_freeze
    self
  end
end
mutate!() click to toggle source
# File lib/wardrobe/plugins/immutable.rb, line 31
def mutate!
  return self if IMMUTABLE_CORE_CLASSES.include?(self.class)
  dup.instance_exec do
    instance_variable_set(:@_mutating, true)
    self
  end
end