Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8332461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:43:52+00:00 2026-06-09T02:43:52+00:00

What differences, if any, exist between the Kernel#at_exit method and the END (all upper

  • 0

What differences, if any, exist between the Kernel#at_exit method and the END (all upper case) keyword? Is the latter merely a more Perlish way of doing things, and the former more Ruby-esque?

I tried doing defined?(END {puts "Bye"}), but got a syntax error.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:43:54+00:00Added an answer on June 9, 2026 at 2:43 am

    “The Ruby Programming Language” defines a minor difference in their behavior. at_exit can be called multiple times when within a loop and each iterated call will be executed when the code exits. END will only be called once when inside a loop.

    …If an END statement is within a loop and is executed
    more than once, then the code associated with it is still only registered once:

    a = 4;
    if (true)
      END { # This END is executed
      puts "if"; # This code is registered
      puts a # The variable is visible; prints "4"
    }
    else
      END { puts "else" } # This is not executed
    end
    10.times {END { puts "loop" }} # Only executed once
    

    The Kernel method at_exit provides an alternative to the END statement; it registers a
    block of code to be executed just before the interpreter exits. As with END blocks, the
    code associated with the first at_exit call will be executed last. If the at_exit method
    is called multiple times within a loop, then the block associated with it will be executed
    multiple times when the interpreter exits.

    So, running:

    2.times {
      END { puts 'END'}
      at_exit { puts 'at_exit' }
    }
    

    results in:

    at_exit
    at_exit
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to determine if any differences exist between a number of fields
There are any differences between using SetValue with (for example) Canvas.LeftProperty and Margin Property?
Are there any differences between LEA $1000,A0 and MOVE #$1000,A0 to put an address
Are there any differences in functionality between these two JavaScript module patterns? var MODULE
Are there any differences when it comes to performance between the following three border
Is there any differences between : > file and > file ? $ :
Are there any differences between get_object_vars($obj) and (array) $obj ? Both seem to return
Say table1 and table2 already exist, is there any difference between these queries query1
Are there any differences using <!--[if lt IE 7]>...<![endif]--> or <!--[if lte IE 6]>...<![endif]-->
I wonder does it make any differences? If its declared in our m file,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.