Class: Creamerscript::Sweeteners::MethodDefinition

Inherits:
Base
  • Object
show all
Defined in:
lib/creamerscript/sweeteners/method_definition.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

Constructor Details

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

Instance Method Details

#argumentsObject



32
33
34
# File 'lib/creamerscript/sweeteners/method_definition.rb', line 32

def arguments
  parameter_names.join(", ")
end

#constructorObject



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

def constructor
  "constructor: (#{arguments}) ->"
end

#definition_with_argumentsObject



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

def definition_with_arguments
  "#{method_name}: (#{arguments}) =>"
end

#definition_without_argumentsObject



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

def definition_without_arguments
  "#{method_name}: =>"
end

#method_nameObject



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

def method_name
  signature_keys.join("_")
end

#patternObject



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

def pattern
  /def #{SYMBOL}(?::#{SYMBOL})?(?:\s+#{SYMBOL}:#{SYMBOL})*/
end

#to_coffeeObject



8
9
10
11
12
13
14
# File 'lib/creamerscript/sweeteners/method_definition.rb', line 8

def to_coffee
  if method_name =~ /^constructor/
    constructor
  else
    arguments.empty? ? definition_without_arguments : definition_with_arguments
  end
end

#typeObject



36
37
38
# File 'lib/creamerscript/sweeteners/method_definition.rb', line 36

def type
  :method_definition
end