Class: Creamerscript::Sweeteners::MethodDefinition
- Inherits:
-
Base
- Object
- Base
- Creamerscript::Sweeteners::MethodDefinition
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
Instance Method Details
#arguments ⇒ Object
32
33
34
|
# File 'lib/creamerscript/sweeteners/method_definition.rb', line 32
def arguments
parameter_names.join(", ")
end
|
#constructor ⇒ Object
16
17
18
|
# File 'lib/creamerscript/sweeteners/method_definition.rb', line 16
def constructor
"constructor: (#{arguments}) ->"
end
|
#definition_with_arguments ⇒ Object
24
25
26
|
# File 'lib/creamerscript/sweeteners/method_definition.rb', line 24
def definition_with_arguments
"#{method_name}: (#{arguments}) =>"
end
|
#definition_without_arguments ⇒ Object
20
21
22
|
# File 'lib/creamerscript/sweeteners/method_definition.rb', line 20
def definition_without_arguments
"#{method_name}: =>"
end
|
#method_name ⇒ Object
28
29
30
|
# File 'lib/creamerscript/sweeteners/method_definition.rb', line 28
def method_name
signature_keys.join("_")
end
|
4
5
6
|
# File 'lib/creamerscript/sweeteners/method_definition.rb', line 4
def pattern
/def #{SYMBOL}(?::#{SYMBOL})?(?:\s+#{SYMBOL}:#{SYMBOL})*/
end
|
#to_coffee ⇒ Object
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
|
36
37
38
|
# File 'lib/creamerscript/sweeteners/method_definition.rb', line 36
def type
:method_definition
end
|