Skip to content

Inconsistency between RescueNode and EnsureNode #334

@dvandersluis

Description

@dvandersluis
ruby-parse -e '
begin
  foo
  bar
rescue StandardError => e
  baz
ensure
  quux
end
'
(kwbegin
  (ensure
    (rescue
      (begin                                <---------- A
        (send nil :foo)
        (send nil :bar))
      (resbody
        (array
          (const nil :StandardError))
        (lvasgn :e)
        (send nil :baz)) nil)
    (send nil :quux)))                      <---------- B

RescueNode.body returns the body of the begin...end block (marked A above). It has resbody_branches and branches to access the bodies of each rescue branch.

EnsureNode.body returns the body of the ensure branch (marked B above). It has currently no method to return the begin...end block, which may or may not be inside a rescue node.

I'd like to have an EnsureNode.body method that mirrors RescueNode.body (ie. returns the code before rescue/ensure), but the method name is already in use for something inconsistent.

  1. Would it be okay to rename EnsureNode.body? I'd update rubocop/extensions to match once released.
  2. If not, what could the method to return A be called on EnsureNode?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions