module Pakyow::Support::DeepFreeze

Public Class Methods

extended(subclass) click to toggle source
Calls superclass method
# File lib/pakyow/support/deep_freeze.rb, line 8
def self.extended(subclass)
  subclass.instance_variable_set(:@unfreezable_variables, [])

  super
end

Public Instance Methods

deep_freeze() click to toggle source
# File lib/pakyow/support/deep_freeze.rb, line 27
def deep_freeze
  unless frozen? || !respond_to?(:freeze)
    self.freeze
    freezable_variables.each do |name|
      instance_variable_get(name).deep_freeze
    end
  end

  self
end
freezable_variables() click to toggle source
# File lib/pakyow/support/deep_freeze.rb, line 38
        def freezable_variables
  object = if self.is_a?(Class) || self.is_a?(Module)
    self
  else
    self.class
  end

  if object.instance_variable_defined?(:@unfreezable_variables)
    instance_variables - object.instance_variable_get(:@unfreezable_variables)
  else
    instance_variables
  end
end
inherited(subclass) click to toggle source
Calls superclass method
# File lib/pakyow/support/deep_freeze.rb, line 14
def inherited(subclass)
  subclass.instance_variable_set(:@unfreezable_variables, @unfreezable_variables)

  super
end
unfreezable(*ivars) click to toggle source
# File lib/pakyow/support/deep_freeze.rb, line 20
def unfreezable(*ivars)
  @unfreezable_variables.concat(ivars.map { |ivar| :"@#{ivar}" })
  @unfreezable_variables.uniq!
end