class Ivar::ExplicitDeclaration

Represents an explicit declaration from the ivar macro

def add_accessor_methods(klass)

Parameters:
  • klass (Class, Module) -- The class to add methods to
def add_accessor_methods(klass)
  var_name = @name.to_s.delete_prefix("@")
  klass.__send__(:attr_reader, var_name) if @reader || @accessor
  klass.__send__(:attr_writer, var_name) if @writer || @accessor
end

def before_init(instance, args, kwargs)

Parameters:
  • kwargs (Hash) -- Keyword arguments
  • args (Array) -- Positional arguments
  • instance (Object) -- The object being initialized
def before_init(instance, args, kwargs)
  if @init_block
    instance.instance_variable_set(@name, @init_block.call(@name))
  end
  if @initial_value != Ivar::Macros::UNSET
    instance.instance_variable_set(@name, @initial_value)
  end
end

def initialize(name, manifest, options = {})

Parameters:
  • options (Hash) -- Options for the declaration
  • name (Symbol, String) -- The name of the instance variable
def initialize(name, manifest, options = {})
  super(name, manifest)
  @init_method = options[:init]
  @initial_value = options[:value]
  @reader = options[:reader] || false
  @writer = options[:writer] || false
  @accessor = options[:accessor] || false
  @init_block = options[:block]
end

def kwarg_init? = false

Returns:
  • (Boolean) - Whether this declaration uses keyword argument initialization
def kwarg_init? = false

def on_declare(klass)

Parameters:
  • klass (Class, Module) -- The class or module the declaration is added to
def on_declare(klass)
  add_accessor_methods(klass)
end