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 8482669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:52:44+00:00 2026-06-10T19:52:44+00:00

I want to emphasize I am looking for the actual way the ||= operator

  • 0

I want to emphasize I am looking for the actual way the ||= operator is expanded by the Ruby 1.9.3 interpreter, not how it appears to be expanded based on its behavior. What I’m really hoping for is someone who has grokked the actual interpreter source, a task which I sadly am probably not up to. The only resource I have found that appears to examine this question is out of date: “A short-circuit (||=) edge case“.

The resource I mentioned above seems to suggest that the “official” expansion of x ||= y to x = x || y was either inaccurate or buggy in interpreter versions prior to 1.9. In any case, the edge case indicated seems to have been smoothed out. The resource above claims that x || x = y or x or x = y are “more accurate”. Neither of those, however, is correct, because they don’t work when x is a previously undeclared global variable:

[11:04:18][****@asha:~]$ irb
1.9.3-p194 :001 > a || a = 3
    NameError: undefined local variable or method `a' for main:Object
1.9.3-p194 :002 > b or b = 3
    NameError: undefined local variable or method `b' for main:Object
1.9.3-p194 :003 > c = c || 3
    => 3 

So in 1.9.3, at least, the x = x || y expansion appears to be correct, as far as these examples are concerned. However, to reiterate my original point, I would really like to see some truly authoritative source resolve this question, well, authoritatively rather than anecdotally as I (and others) have done.

  • 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-10T19:52:45+00:00Added an answer on June 10, 2026 at 7:52 pm

    EDIT: This post is about the spec, read the comments to get the somewhat less ideal “implementation story”


    The Ruby draft spec (PDF) section 11.4.2.3.2 defines it fairly specifically (even if fairly hard to interpret); let’s do a (theoretically somewhat loose) example with c ||= 3;

    a) Evaluate the variable as a variable reference (see 11.5.4). Let V be the resulting value.

    V is set to the value of c

    b) Evaluate the operator-expression or the method-invocation-without-parentheses. Let W be the resulting value.

    W is set to 3.

    c) Let OP be the assignment-operator-name of the assignment-operator.

    OP is set to ||

    d) Let X be the operator-expression of the form V OP W.

    X is set to c || 3.

    e) Let I be the variable of the abbreviated-variable-assignment-expression or the abbreviated- variable-assignment-statement.

    I is set to refer to c.

    f) Evaluate a single-variable-assignment-expression (see 11.4.2.2.2) where its variable is I and the operator-expression is X.

    c = c || 3 is evaluated.

    g) The value of the abbreviated-variable-assignment is the resulting value of the evaluation.

    The result of the assignment is 3.

    In other words, the expansion c = c || 3 is (excluding bugs like in pre-1.9) correct.

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

Sidebar

Related Questions

want to rewrite urls like site.com/software to wp-content/themes/dir/software.php and something is not working.. Here's
want to ask user to input something but not want to wait forever. There
I have a ListView full of ListViewItems. I want to emphasize some of them
I am a beginning C programmer (though not a beginning programmer) looking to dive
I'm looking for a very straight-forward way of getting the version of the TCL
I am using the Python ElementTree module to manipulate HTML. I want to emphasize
I want to emphasize the 3.5 in the question. I am aware that a
Using ruby-graphviz, I've created a graph that looks like this (border added to emphasize
want to open pdf file when a user clicks on hyperlink shown in gridview
Want to run javascript function from parent window in child window Example I have

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.