Module: Hashira::Smells::Parameters
- Defined in:
- lib/hashira/smells/contexts.rb
Constant Summary collapse
- NAMELESS =
[Prism::ForwardingParameterNode, Prism::ImplicitRestNode, Prism::NoKeywordsParameterNode].freeze
Class Method Summary collapse
- .arguments(def_node) ⇒ Object
- .expand(part) ⇒ Object
- .names(def_node) ⇒ Object
- .parts(def_node) ⇒ Object
- .pieces(part) ⇒ Object
Class Method Details
.arguments(def_node) ⇒ Object
14 |
# File 'lib/hashira/smells/contexts.rb', line 14 def arguments(def_node) = parts(def_node).grep_v(Prism::BlockParameterNode).flat_map { (it) } |
.expand(part) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/hashira/smells/contexts.rb', line 23 def (part) case part when Prism::MultiTargetNode then pieces(part).flat_map { (it) } when *NAMELESS then [] else [part.name].compact end end |
.names(def_node) ⇒ Object
12 |
# File 'lib/hashira/smells/contexts.rb', line 12 def names(def_node) = parts(def_node).flat_map { (it) } |
.parts(def_node) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/hashira/smells/contexts.rb', line 16 def parts(def_node) node = def_node.parameters return [] unless node node.requireds + node.optionals + node.posts + node.keywords + [node.rest, node.keyword_rest, node.block].compact end |
.pieces(part) ⇒ Object
31 |
# File 'lib/hashira/smells/contexts.rb', line 31 def pieces(part) = part.lefts + Array(part.rest&.expression) + part.rights |