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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:44:48+00:00 2026-06-09T13:44:48+00:00

Many methods in Ruby array return an enumerator when invoked without parameters or blocks

  • 0

Many methods in Ruby array return an enumerator when invoked without parameters or blocks (index, keep_if, each, drop_while and many more).

  • When is it appropriate to use methods in this form, as opposed to calling them with a block?
  • 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-09T13:44:49+00:00Added an answer on June 9, 2026 at 1:44 pm

    From the docs to Enumerator:

    Most methods have two forms: a block form where the contents are
    evaluated for each item in the enumeration, and a non-block form which
    returns a new Enumerator wrapping the iteration.

    This allows you to chain Enumerators together. For example, you can
    map a list’s elements to strings containing the index and the element
    as a string via:

    puts %w[foo bar baz].map.with_index {|w,i| "#{i}:#{w}" }
    # => ["0:foo", "1:bar", "2:baz"]
    

    An Enumerator can also be used as an external iterator. For example,
    Enumerator#next returns the next value of the iterator or raises
    StopIteration if the Enumerator is at the end.

    e = [1,2,3].each   # returns an enumerator object.
    puts e.next   # => 1
    puts e.next   # => 2
    puts e.next   # => 3
    puts e.next   # raises StopIteration
    

    I’m sorry for copy-paste, but I couldn’t explain better.

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

Sidebar

Related Questions

I see many methods that specify an interface as return value. Is my thought
I have a toolkit that has many methods often taking Expression<Func<T,TProperty>> as parameters. Some
Many methods in the BCL are marked with the [MethodImpl(MethodImplOptions.InternalCall)] attribute. This indicates that
Many methods like stop() , resume() , suspend() etc are deprecated. So is it
For many methods in .NET, the exceptions they can potentially throw can be as
There are many methods for representing structure of a program (like UML class diagrams
I have a WCF service with many methods. I would like that after executing
I currently offer a service with many methods via WCF. I'd like to refactor
I have a class with many methods. How can I modify my methods so
For example, many methods in frameworks/JDK might throw java.lang.SecurityException but this is not indicated

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.