Module: Ivar::Checked::InstanceMethods

Defined in:
lib/ivar/checked/instance_methods.rb

Overview

Instance methods that will be prepended to the including class. These methods provide the core functionality for automatic instance variable validation.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepend_features(othermod) ⇒ Object

The semantics of prepend are such that the super method becomes wholly inaccessible. So if we override a method (like, say, initialize), we have to stash the original method implementation if we ever want to find out its file and line number.



11
12
13
14
15
16
# File 'lib/ivar/checked/instance_methods.rb', line 11

def self.prepend_features(othermod)
  (instance_methods(false) | private_instance_methods(false)).each do |method_name|
    Ivar.stash_method(othermod, method_name)
  end
  super
end

Instance Method Details

#initialize(*args, **kwargs, &block) ⇒ Object

Wrap the initialize method to automatically call check_ivars This method handles the initialization process, including:

  1. Processing manifest declarations before calling super

  2. Checking instance variables for validity



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/ivar/checked/instance_methods.rb', line 22

def initialize(*args, **kwargs, &block)
  if @__ivar_skip_init
    super
  else
    @__ivar_skip_init = true
    manifest = Ivar.get_or_create_manifest(self.class)
    manifest.process_before_init(self, args, kwargs)
    super
    check_ivars
  end
end