Module: Yoda::AST::Vnode::CommentAssociation
- Included in:
- Yoda::AST::Vnode
- Defined in:
- lib/yoda/ast/vnode.rb
Instance Method Summary collapse
- #all_nodes_lazy ⇒ Enumerable<Vnode>
- #associate_comments(comments) ⇒ Hash{Vnode => Array<Parser::Source::Comment>}
- #comments ⇒ Object
- #wrapping?(node) ⇒ boolean
Instance Method Details
#all_nodes_lazy ⇒ Enumerable<Vnode>
96 97 98 |
# File 'lib/yoda/ast/vnode.rb', line 96 def all_nodes_lazy [self, *children].lazy.flat_map { |el| self == el ? self : el.all_nodes_lazy } end |
#associate_comments(comments) ⇒ Hash{Vnode => Array<Parser::Source::Comment>}
79 80 81 82 83 84 85 86 87 |
# File 'lib/yoda/ast/vnode.rb', line 79 def associate_comments(comments) if node = try(:node) Parser::Source::Comment.associate(node, comments).map do |ast_key_node, comments| [all_nodes_lazy.find { |node| node.wrapping?(ast_key_node) }, comments] end.to_h else {} end end |
#comments ⇒ Object
101 102 103 |
# File 'lib/yoda/ast/vnode.rb', line 101 def comments @comments ||= comments_by_node[node] || [] end |
#wrapping?(node) ⇒ boolean
91 92 93 |
# File 'lib/yoda/ast/vnode.rb', line 91 def wrapping?(node) try(:node) && try(:node) == node end |