Class: DevScripts::Support::FlattenedMethod

Inherits:
ExpandedMethod show all
Defined in:
lib/dev_scripts/support/expanded_method.rb

Constant Summary

Constants inherited from ExpandedMethod

ExpandedMethod::INDENT

Instance Method Summary collapse

Constructor Details

#initialize(ast_node:) ⇒ FlattenedMethod

Returns a new instance of FlattenedMethod.

Raises:



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/dev_scripts/support/expanded_method.rb', line 96

def initialize(ast_node:)
  @type = ast_node.type
  @children = ast_node.children

  raise NotAMethodError unless [:send, :block].include?(type)

  get_components

  self << string_receiver

  args.each_with_index do |arg, index|
    if index == 0
      self << '('
    end
    self << string_arg(arg)
    self << "," unless index == args.length - 1
    self << ")" if index == args.length - 1
  end

  case type
  when :block
    self << ' { '
    self << string_block_body
    self << ' }'
  end
end