module Reek::AST::SexpExtensions::ModuleNodeBase
Base module for utility methods for module nodes.
Public Instance Methods
Source
# File lib/reek/ast/sexp_extensions/module.rb, line 81 def direct_children contents = children.last or return [] contents.statements end
In the AST
, the set of children of a module that a human might identify is coded in three different ways.
If there are no children, the last element of the module node is nil, like so:
s(:class, s(:const, nil, :C), nil, nil)
If there is one child, the last element of the module node is that child, like so:
s(:class, s(:const, nil, :C), nil, s(:def, :f, s(:args), nil))
If there is more than one child, those are wrapped as children in a node of type :begin, like so:
s(:class, s(:const, nil, :Alfa), nil, s(:begin, s(:def, :bravo, s(:args), nil), s(:class, s(:const, nil, :Charlie), nil, nil)))
This method unifies those three ways to avoid having to handle them differently.
@return an array of directly visible children of the module
Source
# File lib/reek/ast/sexp_extensions/module.rb, line 43 def name children.first.format_to_ruby end