Class: DissociatedIntrospection::MethodCall

Inherits:
Object
  • Object
show all
Defined in:
lib/dissociated_introspection/method_call.rb

Defined Under Namespace

Classes: Argument

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ruby_code) ⇒ MethodCall

Returns a new instance of MethodCall.



25
26
27
# File 'lib/dissociated_introspection/method_call.rb', line 25

def initialize(ruby_code)
  @ruby_code = ruby_code
end

Instance Attribute Details

#ruby_codeObject (readonly)

Returns the value of attribute ruby_code.



23
24
25
# File 'lib/dissociated_introspection/method_call.rb', line 23

def ruby_code
  @ruby_code
end

Instance Method Details

#argumentsObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dissociated_introspection/method_call.rb', line 29

def arguments
  ruby_code.ast.children[2..-1].map do |c|
    case c.type
    when :sym, :str
      c.to_a.first
    when :block
      Lambda.new(c)
    else
      c
    end
  end
end

#nameObject



42
43
44
# File 'lib/dissociated_introspection/method_call.rb', line 42

def name
  ruby_code.ast.children[1]
end

#to_hObject



46
47
48
# File 'lib/dissociated_introspection/method_call.rb', line 46

def to_h
  { name: name, arguments: arguments }
end