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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:26:02+00:00 2026-05-21T11:26:02+00:00

Possible Duplicate: Array#each vs. Array#map ruby-1.9.2-p180 :006 > ary = [a, b] => [a,

  • 0

Possible Duplicate:
Array#each vs. Array#map

ruby-1.9.2-p180 :006 > ary = ["a", "b"]
 => ["a", "b"] 
ruby-1.9.2-p180 :007 > ary.map { |val| p val }
"a"
"b"
 => ["a", "b"] 
ruby-1.9.2-p180 :008 > ary.each { |val| p val }
"a"
"b"
 => ["a", "b"] 

ruby-1.9.2-p180 :009 > ary.map { |val| val << "2" }
 => ["a2", "b2"] 
ruby-1.9.2-p180 :010 > ary.each { |val| val << "2" }
 => ["a22", "b22"] 
  • 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-21T11:26:02+00:00Added an answer on May 21, 2026 at 11:26 am

    The side effects are the same which is adding some confusion to your reverse engineering.

    Yes, both iterate over the array (actually, anything that mixes in Enumerable) but map will return an Array composed of the block results while each will just return the original Array. The return value of each is rarely used in Ruby code but map is one of the most important functional tools.

    BTW, you may be having a hard time finding the documentation because map is a method in Enumerable while each (the one method required by the Enumerable module) is a method in Array.

    As a trivia note: the map implementation is based on each.

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

Sidebar

Related Questions

Possible Duplicate: What Ruby IDE do you prefer? I've generally been doing stuff on
Possible Duplicate: Array versus List<T>: When to use which? Is there any best practice
Possible Duplicate: C pointer to array/array of pointers disambiguation In C, is int *thing[5]
Possible Duplicate: In PHP, how do you change the key of an array element?
Possible Duplicate: Array of zero length I have seen such type of code :-
Possible Duplicate: How to copy part of an array to another array in C#
Possible Duplicate: What is the Maximum Size that an Array can hold? i want
Possible Duplicate: When should I use stdClass and when should I use an array
Possible Duplicate: What is the LINQ way to implode/join a string array? Say I
Possible Duplicate: Getting the submatrix with maximum sum? Given a 2-dimensional array of positive

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.