Skip to content

Commit

Permalink
Add Node#parent?
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed Sep 24, 2020
1 parent 746171c commit b507420
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

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

## 0.4.2 (2020-09-18)

### Bug fixes
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 b507420

Please sign in to comment.