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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:36:02+00:00 2026-05-20T06:36:02+00:00

Currently, I’m reading "The Well-Grounded Rubyist" by David A. Black, and I’m stuck at

  • 0

Currently, I’m reading "The Well-Grounded Rubyist" by David A. Black, and I’m stuck at chapter 10.9 (Enumerators and the next dimension of enumerability). My question is about the yield method.
What is the meaning of the word yield in the Ruby context? My native language is Russian, and Google Translate shows me a bunch of translation variants, that are confusing me. Some of them are: give, bring, surrender (give up), produce, agree, comply and many others.

UPD: please, pay attention to the fact, that I’m trying to understand the meaning of the Enumerator::Yielder#yield method, but not the yield keyword itself.

UPD_2: I’ve found an interesting article about Enumerators: "Lazy Enumerators in Ruby".

  • 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-20T06:36:02+00:00Added an answer on May 20, 2026 at 6:36 am

    The word yield doesn’t really have any special meaning in the context of Ruby. It means the same thing as it means in every other programming language, or in programming and computer science in general.

    It is usually used when some kind of execution context surrenders control flow to a different execution context. For example, in Unix, there is a sched_yield function which a thread can use to give up the CPU to another thread (or process). With coroutines, the term yield is generally used to transfer control from one coroutine to another. In C#, there is a yield keyword, which is used by an iterator method to give up control to the iterating method.

    And in fact, this last usage is exactly identical to the usage of the Enumerator::Yielder#yield method in Ruby, which you were asking about. Calling this method will suspend the enumerator and give up control to the enumerating method.

    Example:

    fibs = Enumerator.new do |y|
      a, b = 0, 1
      y.yield a
      loop do
        y.yield b
        a, b = b, a + b
      end
    end
    
    puts fibs.next #  0
    puts fibs.next #  1
    puts fibs.next #  1
    puts fibs.next #  2
    puts fibs.next #  3
    puts fibs.next #  5
    puts fibs.next #  8
    puts fibs.next # 13
    puts fibs.next # 21
    

    As you see, there is an infinite loop. Obviously, if this loop just ran on its own, it wouldn’t be of much use. But since every time it hits the yield method, it gives up control until it is called again, this will produce the Fibonacci numbers one by one, essentially representing an infinitely long list of all Fibonacci numbers.

    There is another method, Fiber.yield, which serves a similar purpose. (In fact, I already described it above, because Fiber is just Ruby’s name for coroutines.) Inside a Fiber, you call Fiber.yield to give up control back to the execution context that originally gave control to you.

    Lastly, there is the yield keyword, which is used inside a method body to give up control to the block that was passed into the method.

    Note that, at least in the Enumerator case (i.e. the first example), you can additionally interpret yield as to produce, since the Enumerator produces a new value, every time it calls yield.

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

Sidebar

Related Questions

Currently I'm prototyping search with Lucene.Net-2.0-004 on a web application. It's working very well,
Currently, I know there are several official Android styles. @android:style/Theme.Black @android:style/Theme.Light @android:style/Theme.Translucent But I
Currently we use jQuery to add RIA goodness to our apps, but recently we
Currently I have a class that looks like this: public class MyClass : IMyClass
Currently the HashSet<T> constructor that allows you to define your equality comparison yourself is
Currently developing an application using the newest version of symfony, obtained through PEAR. This
Currently I'm trying to write my first Python library and I've encountered the following
Currently we're parsing arp request output from the command line. string cmd = arp
Currently I have a DetailsView attached to a GridView. When you select an item
Currently ASP.NET MVC's OutputCache attribute has a huge downfall. If you want to cache

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.