Module: Synvert::Core::Rewriter::Helper
- Included in:
- Instance
- Defined in:
- lib/synvert/core/rewriter/helper.rb
Overview
Rewriter::Helper provides some helper methods to make it easier to write a snippet.
Instance Method Summary collapse
-
#add_arguments_with_parenthesis_if_necessary ⇒ String
Add arguments with parenthesis if necessary.
-
#add_receiver_if_necessary(code) ⇒ String
Add receiver to code if necessary.
-
#strip_brackets(code) ⇒ String
Remove leading and trailing brackets.
Instance Method Details
#add_arguments_with_parenthesis_if_necessary ⇒ String
Add arguments with parenthesis if necessary.
35 36 37 38 39 40 41 |
# File 'lib/synvert/core/rewriter/helper.rb', line 35 def add_arguments_with_parenthesis_if_necessary if node.arguments.size > 0 "({{arguments}})" else "" end end |
#add_receiver_if_necessary(code) ⇒ String
Add receiver to code if necessary.
17 18 19 20 21 22 23 |
# File 'lib/synvert/core/rewriter/helper.rb', line 17 def add_receiver_if_necessary(code) if node.receiver "{{receiver}}.#{code}" else code end end |
#strip_brackets(code) ⇒ String
Remove leading and trailing brackets.
51 52 53 54 55 |
# File 'lib/synvert/core/rewriter/helper.rb', line 51 def strip_brackets(code) code.sub(/^\((.*)\)$/) { $1 } .sub(/^\[(.*)\]$/) { $1 } .sub(/^{(.*)}$/) { $1 } end |