Skip to content

Commit

Permalink
Add Node#parent? and Node#root?
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre authored and mergify[bot] committed Sep 24, 2020
1 parent 4adf4b2 commit aa7975e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### New features

* [#122](https://github.com/rubocop-hq/rubocop-ast/pull/122): Add `Node#parent?` and `Node#root?`. ([@marcandre][])

### Changes

* [#121](https://github.com/rubocop-hq/rubocop-ast/pull/121): Update from `Parser::Ruby28` to `Parser::Ruby30` for Ruby 3.0 parser (experimental). ([@koic][])
Expand Down
10 changes: 10 additions & 0 deletions lib/rubocop/ast/node.rb
Expand Up @@ -92,6 +92,16 @@ def parent=(node)
@mutable_attributes[:parent] = node
end

# @return [Boolean]
def parent?
!!parent
end

# @return [Boolean]
def root?
!parent
end

def complete!
@mutable_attributes.freeze
each_child_node(&:complete!)
Expand Down

0 comments on commit aa7975e

Please sign in to comment.