Class: Creamerscript::Sweeteners::MethodInvocation

Inherits:
Base
  • Object
show all
Defined in:
lib/creamerscript/sweeteners/method_invocation.rb

Constant Summary

Constants inherited from Base

Base::SYMBOL

Instance Attribute Summary

Attributes inherited from Base

#source, #substitutions

Instance Method Summary collapse

Methods inherited from Base

#call, #initialize, #substitute, #token, #tokenize, #type

Constructor Details

This class inherits a constructor from Creamerscript::Sweeteners::Base

Instance Method Details

#argumentsObject



28
29
30
# File 'lib/creamerscript/sweeteners/method_invocation.rb', line 28

def arguments
  parameter_values.join(", ")
end

#initializerObject



12
13
14
# File 'lib/creamerscript/sweeteners/method_invocation.rb', line 12

def initializer
  "new #{subject}(#{arguments})"
end

#method_nameObject



24
25
26
# File 'lib/creamerscript/sweeteners/method_invocation.rb', line 24

def method_name
  signature_keys.join("_")
end

#normal_method_callObject



16
17
18
# File 'lib/creamerscript/sweeteners/method_invocation.rb', line 16

def normal_method_call
  "#{subject}.#{method_name}(#{arguments})"
end

#patternObject



4
5
6
# File 'lib/creamerscript/sweeteners/method_invocation.rb', line 4

def pattern
  /\(#{SYMBOL} #{SYMBOL}[^\(\)]+\)/m
end

#subjectObject



20
21
22
# File 'lib/creamerscript/sweeteners/method_invocation.rb', line 20

def subject
  body.split.first
end

#to_coffeeObject



8
9
10
# File 'lib/creamerscript/sweeteners/method_invocation.rb', line 8

def to_coffee
  method_name =~ /^new/ ? initializer : normal_method_call
end