Module: LiveAST::Attacher

Included in:
Linker
Defined in:
lib/live_ast/linker.rb

Constant Summary collapse

VAR_NAME =
:@_live_ast

Instance Method Summary collapse

Instance Method Details

#attach_to_method(klass, method, ast) ⇒ Object



30
31
32
33
34
35
# File 'lib/live_ast/linker.rb', line 30

def attach_to_method(klass, method, ast)
  unless klass.instance_variable_defined?(VAR_NAME)
    klass.instance_variable_set(VAR_NAME, {})
  end
  klass.instance_variable_get(VAR_NAME)[method] = ast
end

#attach_to_proc(obj, ast) ⇒ Object



22
23
24
# File 'lib/live_ast/linker.rb', line 22

def attach_to_proc(obj, ast)
  obj.instance_variable_set(VAR_NAME, ast)
end

#fetch_method_attachment(klass, method) ⇒ Object



37
38
39
40
41
# File 'lib/live_ast/linker.rb', line 37

def fetch_method_attachment(klass, method)
  if klass.instance_variable_defined?(VAR_NAME)
    klass.instance_variable_get(VAR_NAME)[method]
  end
end

#fetch_proc_attachment(obj) ⇒ Object



26
27
28
# File 'lib/live_ast/linker.rb', line 26

def fetch_proc_attachment(obj)
  obj.instance_variable_get(VAR_NAME) if obj.instance_variable_defined?(VAR_NAME)
end