Mike Perham

On Ruby, software and the Internet

Ruby Scoping Oddity

May 22nd, 2008 · 1 Comment

This prints out “1″:

  begin
    a = 1
    raise RuntimeError, "foo"
  rescue => e
    puts a
  end

I would think that a would be out of scope inside the rescue section but I guess Ruby considers the rescue section part of the begin/end block?

Tags: Ruby · Software

1 response so far ↓

  • 1 Adam Keys // May 22, 2008 at 5:38 pm

    This is probably related to the situation where


    5.times { a = 4 }
    puts a

    used to print 4.

Leave a Comment