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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:53:46+00:00 2026-06-13T02:53:46+00:00

I noticed some interesting use of ||= as below – Code 1 array_1 ||=

  • 0

I noticed some interesting use of ||= as below –

Code 1

array_1 ||= begin
    (1..5).to_a.map {|el| el*10}
end
puts array_1.to_s # [10,20,30,40,50]

So I executed its following modified version –

Code 2

array_2 ||= def some_method
    (1..5).to_a.map {|el| el*10}
end
puts array_2 # prints nothing
puts array_2.class # NilClass
puts some_method.to_s # [10,20,30,40,50]
  1. Why does array_2 gets initialised to nil?
  2. Is it possible to invoke some_method using array_2 object? how?

UPDATE

This is what I did for question 2

array_2 ||= "We've got #{def some_method;(1..5).to_a.map {|el| el*10};end;array_2.send(:some_method)}"
puts array_2 # We've got [10, 20, 30, 40, 50]
  • 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-13T02:53:47+00:00Added an answer on June 13, 2026 at 2:53 am

    The return value of a method definition expression (def) is implementation-defined. Most Ruby implementations simply return nil from a def expression, but Rubinius, for example, returns the compiled code of the method wrapped up in a CompiledMethod object.

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

Sidebar

Related Questions

While inspecting delegates in C# and .NET in general, I noticed some interesting facts:
So I've noticed some very weird behaviour from my program. Here's a simplified code
I ran across an interesting issue in some of my humanize_bytes() code. This loop
I noticed some programmers use unsigned long for tv_sec and tv_usec [when they copy
When using telnetlib I noticed some interesting variables: AUTHENTICATION = chr(37) # Authenticate XAUTH
I have recently noticed how interesting Visual Studio's macros are. I did not use
So I was doing some simple C++ exercises and I noticed an interesting feat.
JSLint has some interesting messages, such as eval is evil. when you use an
I found an interesting issue that confused me. I noticed it when I use
I noticed some confusion initially with my question. I'm not asking about how to

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.