Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return in a proc given to define_method does not return #2370

Open
enebo opened this issue Dec 29, 2014 · 0 comments
Open

Return in a proc given to define_method does not return #2370

enebo opened this issue Dec 29, 2014 · 0 comments

Comments

@enebo
Copy link
Member

enebo commented Dec 29, 2014

Originally from http://jira.codehaus.org/browse/JRUBY-6122

  class DefineMethod
    lamb = proc { return :good }
    define_method :foo, lamb

    def outer
      val = :bad

      # This is tricky, but works. If lamb properly returns, then the
      # return value will go into val before we run the ensure.
      #
      # If lamb's return keeps unwinding incorrectly, val will still
      # have it's old value.
      #
      # We can therefore use val to figure out what happened.
      begin
        val = foo()
      ensure
        if val != :good
          return :bad
        end
      end

      return val
    end
  end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant