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

  • Home
  • SEARCH
  • 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 6772909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:36:15+00:00 2026-05-26T15:36:15+00:00

While reading Programming Ruby , I ran across this code snippet: while gets num1,

  • 0

While reading Programming Ruby, I ran across this code snippet:

while gets
  num1, num2 = split /,/
end

While I intuitively understand what it does, I don’t understand the syntax. ‘split’ is a method on the String class – in Ruby parlance, which string is the receiver of the ‘split’ message in the scenario above?

I can see in the docs that ‘gets’ assigns its result to the variable $_, so my guess is that it is implicitly using $_ as the receiver – but a whole bunch of Google searching has failed to confirm that guess. If that is the case, I’d love to know what general rule for methods called without an explicit receiver.

I did try the code in irb, with some diagnostic puts calls added, and I verified that the actual behavior is what you would expect – num1 and num2 get assigned values that were input separated by a comma.

  • 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-05-26T15:36:16+00:00Added an answer on May 26, 2026 at 3:36 pm

    Ruby 1.8 has a method Kernel#split([pattern [, limit]]) which is identical to $_.split(pattern, limit), and gets sets the value of $_.

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

Sidebar

Related Questions

I am fairly new to programming and while doing a lot of reading this
While reading SICP I came across logic programming chapter 4.4. Then I started looking
While reading Essentials of Programming Languages I came across top down and bottom up
While reading the QTKit Application Programming Guide I came across the term 'headless environments'
while reading on concurrent programming, I came across the term Consensus Number in Compare-And-Swap
While reading the book Programming Ruby , one example shows how blocks can be
I started reading Programming Pearls today and while doing it's exercise I came across
Recently, while reading a Socket Programming HOWTO the following section jumped out at me:
Functional programming .. is like classic ( Mark Twain's type ). While reading another
While reading the answers to this question I got a doubt regarding the default

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.