Class: DissociatedIntrospection::MethodInLiner::InLiner

Inherits:
Parser::TreeRewriter
  • Object
show all
Defined in:
lib/dissociated_introspection/method_in_liner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#defsObject

Returns the value of attribute defs.



20
21
22
# File 'lib/dissociated_introspection/method_in_liner.rb', line 20

def defs
  @defs
end

Instance Method Details

#called_method(method_name) ⇒ Object



35
36
37
# File 'lib/dissociated_introspection/method_in_liner.rb', line 35

def called_method(method_name)
  defs.detect { |_def| _def.name == method_name }
end

#called_on_self?(called_on) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/dissociated_introspection/method_in_liner.rb', line 31

def called_on_self?(called_on)
  called_on.nil? || called_on.type == :self
end

#on_send(node) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/dissociated_introspection/method_in_liner.rb', line 22

def on_send(node)
  called_on, method_name, *args = *node
  # TODO: Deal with args by replacing lvar with passed objects
  return super unless args.empty? && called_on_self?(called_on)
  called_method = called_method(method_name)
  return super unless called_method
  node.updated(called_method.body.ast.type, called_method.body.ast.children)
end