{"id":40261,"date":"2025-11-03T06:35:32","date_gmt":"2025-11-03T06:35:32","guid":{"rendered":"https:\/\/www.railscarma.com\/?p=40261"},"modified":"2025-11-03T06:41:24","modified_gmt":"2025-11-03T06:41:24","slug":"master-ruby-enumerable-each-map-and-select","status":"publish","type":"post","link":"https:\/\/www.railscarma.com\/fr\/blog\/master-ruby-enumerable-each-map-and-select\/","title":{"rendered":"Master Ruby Enumerable: each, map, and select"},"content":{"rendered":"<div data-elementor-type=\"wp-post\" data-elementor-id=\"40261\" class=\"elementor elementor-40261\" data-elementor-post-type=\"post\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-a6fa11e elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"a6fa11e\" data-element_type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-2dc11c6\" data-id=\"2dc11c6\" data-element_type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-08c4140 elementor-widget elementor-widget-text-editor\" data-id=\"08c4140\" data-element_type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Ruby\u2019s <strong>Ruby Enumerable<\/strong> module is the powerhouse behind expressive, functional-style iteration. Mixed into <code>Array, Hash, Range, Set<\/code>, and custom collections, it enables clean, efficient data processing.&nbsp;<span style=\"font-size: 16px;\">Enhance your Ruby projects with expert <\/span><strong data-start=\"39\" data-end=\"68\" style=\"font-size: 16px;\"><a href=\"https:\/\/www.railscarma.com\/fr\/ruby-on-rails-consulting\/\">Rails consulting services<\/a><\/strong><span style=\"font-size: 16px;\">, optimizing each, map, and select for cleaner, high-performance code.<\/span><\/p>\n<article class=\"text-token-text-primary w-full focus:outline-none [--shadow-height:45px] has-data-writing-block:pointer-events-none has-data-writing-block:-mt-(--shadow-height) has-data-writing-block:pt-(--shadow-height) [&amp;:has([data-writing-block])&gt;*]:pointer-events-auto [content-visibility:auto] supports-[content-visibility:auto]:[contain-intrinsic-size:auto_100lvh] scroll-mt-[calc(var(--header-height)+min(200px,max(70px,20svh)))]\" tabindex=\"-1\" dir=\"auto\" data-turn-id=\"request-6902f6ea-1f18-8321-bec2-c21e0beed250-7\" data-testid=\"conversation-turn-74\" data-scroll-anchor=\"true\" data-turn=\"assistant\">\n<div class=\"text-base my-auto mx-auto pb-10 [--thread-content-margin:--spacing(4)] thread-sm:[--thread-content-margin:--spacing(6)] thread-lg:[--thread-content-margin:--spacing(16)] px-(--thread-content-margin)\">\n<div class=\"[--thread-content-max-width:40rem] thread-lg:[--thread-content-max-width:48rem] mx-auto max-w-(--thread-content-max-width) flex-1 group\/turn-messages focus-visible:outline-hidden relative flex w-full min-w-0 flex-col agent-turn\" tabindex=\"-1\">\n<div class=\"z-0 flex min-h-[46px] justify-start\"><\/div>\n<div class=\"mt-3 w-full empty:hidden\">\n<div class=\"text-center\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/article>\n<div aria-hidden=\"true\" data-edge=\"true\" class=\"pointer-events-none h-px w-px\"><\/div>\n<h2><strong>Ruby Enumerable: The Foundation<\/strong><\/h2>\n<p>To use <strong>Ruby Enumerable<\/strong>, a class must define <code>chacun<\/code>:<\/p>\n<pre>ruby\nclass ShoppingList\n  include Enumerable\n\n  def initialize(*items)\n &nbsp;&nbsp; @items = items\n  end\n\n  def each(&amp;block)\n &nbsp;&nbsp; @items.each(&amp;block)\n  end\nend<\/pre>\n<p>Now <code>ShoppingList<\/code> supports <strong>all Ruby Enumerable<\/strong> methods.<\/p>\n<h2><strong>Ruby Enumerable: <\/strong><code>chacun<\/code><strong> \u2013 Execute Per Item<\/strong><\/h2>\n<h4><strong>What <\/strong><code>chacun<\/code><strong> Does<\/strong><\/h4>\n<p>Runs a block for every element. <strong>Returns the original collection.<\/strong><\/p>\n<pre>ruby\n[1, 2, 3].each { |n| puts n * 2 }\n# Output:\n# 2\n# 4\n# 6\n# Returns: [1, 2, 3]<\/pre>\n<h4><strong>When to Use Ruby Enumerable <\/strong><code>chacun<\/code><\/h4>\n<ul>\n<li>Logging or printing<\/li>\n<li>Triggering side effects (email, API calls)<\/li>\n<li>Accumulating external state<\/li>\n<\/ul>\n<pre>ruby\ntotal = 0\n[10, 20, 30].each { |n| total += n }\nputs total # =&gt; 60<\/pre>\n<p><strong><em>Pitfall<\/em><\/strong><em><strong>:<\/strong> Never use <\/em><em><code>chacun<\/code> expecting a transformed array.<\/em><\/p>\n<pre>ruby\n# Wrong\n[1, 2, 3].each { |n| n * 2 } # =&gt; [1, 2, 3]<\/pre>\n<h2><strong>Ruby Enumerable: <\/strong><code>carte<\/code><strong> (ou <\/strong><code>collecter<\/code><strong>) \u2013 Transform Every Item<\/strong><\/h2>\n<h4><strong>What <\/strong><code>carte<\/code><strong> Does<\/strong><\/h4>\n<p>Applies a block and <strong>returns a new array<\/strong> of results.<\/p>\n<pre>ruby\n[1, 2, 3].map { |n| n * 2 } # =&gt; [2, 4, 6]<\/pre>\n<h4><strong>When to Use Ruby Enumerable <\/strong><code>carte<\/code><\/h4>\n<ul>\n<li>Converting data types<\/li>\n<li>Extracting fields<\/li>\n<li>Building new structures<\/li>\n<\/ul>\n<h4><strong>Ruby Enumerable <\/strong><code>carte<\/code><strong> Exemples<\/strong><\/h4>\n<p><strong>Capitalize Names<\/strong><\/p>\n<pre>ruby\n[\"alice\", \"bob\"].map(&amp;:upcase) # =&gt; [\"ALICE\", \"BOB\"]<\/pre>\n<p><strong>Extract User Emails<\/strong><\/p>\n<pre>ruby\nusers = [{email: \"a@x.com\"}, {email: \"b@x.com\"}]\nusers.map { |u| u[:email] } # =&gt; [\"a@x.com\", \"b@x.com\"]<\/pre>\n<p><strong>With Index<\/strong><\/p>\n<pre>ruby\nfruits = [\"apple\", \"banana\"]\nfruits.map.with_index { |f, i| \"#{i + 1}. #{f}\" }\n# =&gt; [\"1. apple\", \"2. banana\"]<\/pre>\n<p><strong><em>Pitfall<\/em><\/strong><em>: Don\u2019t use <\/em><em><code>carte<\/code> for side effects only.<\/em><\/p>\n<pre>ruby\n# Returns [nil, nil, nil]\n[1, 2, 3].map { |n| puts n }<\/pre>\n<h2><strong>Ruby Enumerable: <\/strong><code>s\u00e9lectionner<\/code><strong> (ou <\/strong><code>trouver_tout<\/code><strong>) \u2013 Filter Matching Items<\/strong><\/h2>\n<h4><strong>What <\/strong><code>s\u00e9lectionner<\/code><strong> Does<\/strong><\/h4>\n<p>Returns a <strong>new array<\/strong> of elements where block returns <code>vrai<\/code>.<\/p>\n<pre>ruby\n[1, 2, 3, 4].select(&amp;:even?) # =&gt; [2, 4]<\/pre>\n<h4><strong>When to Use Ruby Enumerable <\/strong><code>s\u00e9lectionner<\/code><\/h4>\n<ul>\n<li>Filtering valid records<\/li>\n<li>Querying data<\/li>\n<li>Subsetting collections<\/li>\n<\/ul>\n<h4><strong>Ruby Enumerable <\/strong><code>s\u00e9lectionner<\/code><strong> Exemples<\/strong><\/h4>\n<p><strong>Passing Scores<\/strong><\/p>\n<pre>ruby\nscores = [89, 45, 92, 61]\nscores.select { |s| s &gt;= 70 } # =&gt; [89, 92]<\/pre>\n<p><strong>Active Users<\/strong><\/p>\n<pre>ruby\nusers = [\n  {name: \"Alice\", active: true},\n  {name: \"Bob\",&nbsp;&nbsp; active: false}\n]\nusers.select { |u| u[:active] } # =&gt; [{name: \"Alice\", active: true}]<\/pre>\n<p><strong>Opposite: <\/strong><code>rejeter<\/code><\/p>\n<pre>ruby\n[1, 2, 3, 4].reject(&amp;:even?) # =&gt; [1, 3]<\/pre>\n<h2><strong>Ruby Enumerable: Key Differences<\/strong><\/h2>\n<table>\n<tbody>\n<tr>\n<th>M\u00e9thode<\/th>\n<th>Returns<\/th>\n<th>Objectif<\/th>\n<\/tr>\n<tr>\n<td><code>chacun<\/code><\/td>\n<td>Original collection<\/td>\n<td>Side effects<\/td>\n<\/tr>\n<tr>\n<td><code>carte<\/code><\/td>\n<td>New array of transformed values<\/td>\n<td>Transform data<\/td>\n<\/tr>\n<tr>\n<td><code>s\u00e9lectionner<\/code><\/td>\n<td>New array of matching elements<\/td>\n<td>Filter data<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2><strong>Ruby Enumerable: Chaining for Power<\/strong><\/h2>\n<p>Chain methods for expressive pipelines:<\/p>\n<pre>ruby\n(1..10)\n  .select(&amp;:even?)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # [2, 4, 6, 8, 10]\n  .map { |n| n ** 2 }&nbsp;&nbsp; # [4, 16, 36, 64, 100]\n  .each { |sq| puts sq }<\/pre>\n<p>Real-world example:<\/p>\n<pre>ruby\nactive_emails = users\n  .select { |u| u[:active] &amp;&amp; u[:age] &gt;= 18 }\n  .map { |u| u[:email] }<\/pre>\n<h2><strong>Ruby Enumerable: Performance Tips<\/strong><\/h2>\n<h4><strong>One Pass &gt; Two<\/strong><\/h4>\n<pre>ruby\n# Slower: two iterations\nusers.map(&amp;:age).select { |a| a &gt; 18 }\n\n# Faster: one iteration\nusers.select { |u| u[:age] &gt; 18 }.map(&amp;:age)<\/pre>\n<h4><strong>Symbol-to-Proc Shorthand<\/strong><\/h4>\n<pre>ruby\nnames.map(&amp;:upcase)<\/pre>\n<h4><strong>Lazy Evaluation for Large\/Infinite Data<\/strong><\/h4>\n<pre>ruby\n(1..Float::INFINITY).lazy\n  .select(&amp;:even?)\n  .map { |n| n * n }\n  .first(5)\n# =&gt; [4, 16, 36, 64, 100]<\/pre>\n<h3><strong>Ruby Enumerable: Bonus Patterns<\/strong><\/h3>\n<h4><strong>Safe Parsing with <\/strong><code>carte<\/code><strong> + <\/strong><code>compact<\/code><\/h4>\n<pre>ruby\n[\"1\", \"2\", \"abc\"].map { |s| Integer(s) rescue nil }.compact\n# =&gt; [1, 2]<\/pre>\n<h4><strong>Find First Match<\/strong><\/h4>\n<pre>ruby\nadmin = users.find { |u| u[:role] == \"admin\" }&nbsp; # Better than select.first<\/pre>\n<h4><strong>Accumulate with <\/strong><code>each_with_object<\/code><\/h4>\n<pre>ruby\n[1, 2, 3].each_with_object({}) { |n, h| h[n] = n * 2 }\n# =&gt; {1=&gt;2, 2=&gt;4, 3=&gt;6}<\/pre>\n<h2><strong>Ruby Enumerable: Final Checklist<\/strong><\/h2>\n<ul>\n<li>Utilisation <code>chacun<\/code> \u2192 side effects<\/li>\n<li>Utilisation <code>carte<\/code> \u2192 transform<\/li>\n<li>Utilisation <code>s\u00e9lectionner<\/code> \u2192 filter<\/li>\n<li>Chain for clarity<\/li>\n<li>Never ignore return values<\/li>\n<li>Prefer <code>trouver<\/code> over <code>select.first<\/code><\/li>\n<li>Utilisation <code>lazy<\/code> for huge\/infinite streams<\/li>\n<\/ul>\n<h2><strong>Conclusion:<\/strong><\/h2>\n<p>The Ruby Enumerable module is more than a collection of methods \u2014 it\u2019s a philosophy of clean, readable, and efficient code. By mastering <code>each, map<\/code>, et <code>s\u00e9lectionner<\/code>, you gain the ability to:<\/p>\n<ul>\n<li><strong>Express intent clearly<\/strong> \u2014 no more confusing loops.<\/li>\n<li><strong>Avoid bugs<\/strong> \u2014 return values matter, and these methods enforce it.<\/li>\n<li><strong>Write performant code<\/strong> \u2014 one-pass operations and lazy evaluation.<\/li>\n<li><strong style=\"font-size: 16px;\">Chain fluently<\/strong><span style=\"font-size: 16px;\"> \u2014 build powerful data pipelines in a single line.<\/span><\/li>\n<\/ul>\n<p>\u00c0 <strong>RailsCarma<\/strong>, l'un des principaux <a href=\"https:\/\/www.railscarma.com\/fr\">Soci\u00e9t\u00e9 de d\u00e9veloppement Ruby on Rails<\/a>, we apply these principles every day to build scalable, maintainable, and elegant applications. Whether it\u2019s filtering users, transforming datasets, or sending notifications, our developers leverage Ruby\u2019s Enumerable power to write code that\u2019s both expressive and efficient.<\/p>\n<p>Practice these methods daily, chain them wisely, and you\u2019ll soon write Ruby the way it was meant to be written \u2014 elegant, expressive, and effortless.<\/p>\n<p>Start today: open your terminal, fire up irb, and experiment with <code>carte, s\u00e9lectionnez<\/code>, et <code>chacun<\/code> on any array. The power \u2014 and the RailsCarma way \u2014 is in your hands.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>\n\t\t  <div class=\"related-post slider\">\r\n        <div class=\"headline\">Articles Similaires<\/div>\r\n    <div class=\"post-list owl-carousel\">\r\n\r\n            <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\"Ruby on Rails pour MLOps : un guide complet pour le d\u00e9ploiement de ML\" href=\"https:\/\/www.railscarma.com\/fr\/blog\/ruby-on-rails-for-mlops-a-complete-guide-to-ml-deployment\/?related_post_from=41350\">\r\n\r\n      <img decoding=\"async\" width=\"800\" height=\"300\" src=\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/05\/Ruby-on-Rails-for-MLOps.png\" class=\"attachment-full size-full wp-post-image\" alt=\"Ruby on Rails pour MLOps\" srcset=\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/05\/Ruby-on-Rails-for-MLOps.png 800w, https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/05\/Ruby-on-Rails-for-MLOps-300x113.png 300w, https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/05\/Ruby-on-Rails-for-MLOps-768x288.png 768w, https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/05\/Ruby-on-Rails-for-MLOps-18x7.png 18w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\"Ruby on Rails pour MLOps : un guide complet pour le d\u00e9ploiement de ML\" href=\"https:\/\/www.railscarma.com\/fr\/blog\/ruby-on-rails-for-mlops-a-complete-guide-to-ml-deployment\/?related_post_from=41350\">\r\n        Ruby on Rails pour MLOps : un guide complet pour le d\u00e9ploiement de ML  <\/a>\r\n\r\n        <\/div>\r\n              <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\"Construire des applications d&#039;IA agentique avec Ruby on Rails\" href=\"https:\/\/www.railscarma.com\/fr\/blog\/building-agentic-ai-applications-with-ruby-on-rails\/?related_post_from=41339\">\r\n\r\n      <img decoding=\"async\" width=\"800\" height=\"300\" src=\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/05\/Building-Agentic-AI-Applications-with-Ruby-on-Rails.png\" class=\"attachment-full size-full wp-post-image\" alt=\"Applications d&#039;IA agentique avec Ruby on Rails\" srcset=\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/05\/Building-Agentic-AI-Applications-with-Ruby-on-Rails.png 800w, https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/05\/Building-Agentic-AI-Applications-with-Ruby-on-Rails-300x113.png 300w, https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/05\/Building-Agentic-AI-Applications-with-Ruby-on-Rails-768x288.png 768w, https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/05\/Building-Agentic-AI-Applications-with-Ruby-on-Rails-18x7.png 18w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\"Construire des applications d&#039;IA agentique avec Ruby on Rails\" href=\"https:\/\/www.railscarma.com\/fr\/blog\/building-agentic-ai-applications-with-ruby-on-rails\/?related_post_from=41339\">\r\n        Construire des applications d'IA agentique avec Ruby on Rails  <\/a>\r\n\r\n        <\/div>\r\n              <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\"Qu&#039;est-ce que Offliberty Ruby Gem et comment fonctionne-t-il ?\" href=\"https:\/\/www.railscarma.com\/fr\/blog\/quest-ce-que-offliberty-ruby-gem-et-comment-fonctionne-t-il\/?related_post_from=41304\">\r\n\r\n      <img decoding=\"async\" width=\"800\" height=\"300\" src=\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/04\/What-is-Offliberty-Ruby-Gem-and-How-It-Works.png\" class=\"attachment-full size-full wp-post-image\" alt=\"Offliberty Ruby Gem\" srcset=\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/04\/What-is-Offliberty-Ruby-Gem-and-How-It-Works.png 800w, https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/04\/What-is-Offliberty-Ruby-Gem-and-How-It-Works-300x113.png 300w, https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/04\/What-is-Offliberty-Ruby-Gem-and-How-It-Works-768x288.png 768w, https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/04\/What-is-Offliberty-Ruby-Gem-and-How-It-Works-18x7.png 18w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\"Qu&#039;est-ce que Offliberty Ruby Gem et comment fonctionne-t-il ?\" href=\"https:\/\/www.railscarma.com\/fr\/blog\/quest-ce-que-offliberty-ruby-gem-et-comment-fonctionne-t-il\/?related_post_from=41304\">\r\n        Qu'est-ce que Offliberty Ruby Gem et comment fonctionne-t-il ?  <\/a>\r\n\r\n        <\/div>\r\n              <div class=\"item\">\r\n            <div class=\"thumb post_thumb\">\r\n    <a  title=\"Comment construire une plateforme SaaS \u00e9volutive en utilisant Ruby on Rails\" href=\"https:\/\/www.railscarma.com\/fr\/blog\/how-to-build-a-scalable-saas-platform-using-ruby-on-rails\/?related_post_from=41273\">\r\n\r\n      <img decoding=\"async\" width=\"800\" height=\"300\" src=\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/04\/Build-a-SaaS-Platform-Using-Ruby-on-Rails.png\" class=\"attachment-full size-full wp-post-image\" alt=\"Construire une plateforme SaaS avec Ruby on Rails\" srcset=\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/04\/Build-a-SaaS-Platform-Using-Ruby-on-Rails.png 800w, https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/04\/Build-a-SaaS-Platform-Using-Ruby-on-Rails-300x113.png 300w, https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/04\/Build-a-SaaS-Platform-Using-Ruby-on-Rails-768x288.png 768w, https:\/\/www.railscarma.com\/wp-content\/uploads\/2026\/04\/Build-a-SaaS-Platform-Using-Ruby-on-Rails-18x7.png 18w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/>\r\n\r\n    <\/a>\r\n  <\/div>\r\n\r\n  <a class=\"title post_title\"  title=\"Comment construire une plateforme SaaS \u00e9volutive en utilisant Ruby on Rails\" href=\"https:\/\/www.railscarma.com\/fr\/blog\/how-to-build-a-scalable-saas-platform-using-ruby-on-rails\/?related_post_from=41273\">\r\n        Comment construire une plateforme SaaS \u00e9volutive en utilisant Ruby on Rails  <\/a>\r\n\r\n        <\/div>\r\n      \r\n  <\/div>\r\n\r\n  <script>\r\n      <\/script>\r\n  <style>\r\n    .related-post {}\r\n\r\n    .related-post .post-list {\r\n      text-align: left;\r\n          }\r\n\r\n    .related-post .post-list .item {\r\n      margin: 10px;\r\n      padding: 10px;\r\n          }\r\n\r\n    .related-post .headline {\r\n      font-size: 14px !important;\r\n      color: #999999 !important;\r\n          }\r\n\r\n    .related-post .post-list .item .post_thumb {\r\n      max-height: 220px;\r\n      margin: 10px 0px;\r\n      padding: 0px;\r\n      display: block;\r\n          }\r\n\r\n    .related-post .post-list .item .post_title {\r\n      font-size: 14px;\r\n      color: #000000;\r\n      margin: 10px 0px;\r\n      padding: 0px;\r\n      display: block;\r\n      text-decoration: none;\r\n          }\r\n\r\n    .related-post .post-list .item .post_excerpt {\r\n      font-size: 12px;\r\n      color: #3f3f3f;\r\n      margin: 10px 0px;\r\n      padding: 0px;\r\n      display: block;\r\n      text-decoration: none;\r\n          }\r\n\r\n    .related-post .owl-dots .owl-dot {\r\n          }\r\n\r\n      <\/style>\r\n      <script>\r\n      jQuery(document).ready(function($) {\r\n        $(\".related-post .post-list\").owlCarousel({\r\n          items: 2,\r\n          responsiveClass: true,\r\n          responsive: {\r\n            0: {\r\n              items: 1,\r\n            },\r\n            768: {\r\n              items: 2,\r\n            },\r\n            1200: {\r\n              items: 2,\r\n            }\r\n          },\r\n                      rewind: true,\r\n                                loop: true,\r\n                                center: false,\r\n                                autoplay: true,\r\n            autoplayHoverPause: true,\r\n                                nav: true,\r\n            navSpeed: 1000,\r\n            navText: ['<i class=\"fas fa-chevron-left\"><\/i>', '<i class=\"fas fa-chevron-right\"><\/i>'],\r\n                                dots: false,\r\n            dotsSpeed: 1200,\r\n                                                    rtl: false,\r\n          \r\n        });\r\n      });\r\n    <\/script>\r\n  <\/div>","protected":false},"excerpt":{"rendered":"<p>Ruby\u2019s Ruby Enumerable module is the powerhouse behind expressive, functional-style iteration. Mixed into Array, Hash, Range, Set, and custom collections, it enables clean, efficient data processing.&nbsp;Enhance your Ruby projects with expert Rails consulting services, optimizing each, map, and select for cleaner, high-performance code. Ruby Enumerable: The Foundation To use Ruby Enumerable, a class must define &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"https:\/\/www.railscarma.com\/fr\/blog\/how-to-build-a-scalable-saas-platform-using-ruby-on-rails\/\"> <span class=\"screen-reader-text\">Comment construire une plateforme SaaS \u00e9volutive en utilisant Ruby on Rails<\/span> Lire la suite \u00bb<\/a><\/p>","protected":false},"author":11,"featured_media":40294,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1224],"tags":[],"class_list":["post-40261","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Master Ruby Enumerable: each, map, and select - RailsCarma<\/title>\n<meta name=\"description\" content=\"Master Ruby Enumerable methods \u2014 each, map, and select \u2014 to write clean, efficient, and expressive Ruby code with better data handling.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.railscarma.com\/fr\/blog\/master-ruby-enumerable-each-map-and-select\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Master Ruby Enumerable: each, map, and select - RailsCarma\" \/>\n<meta property=\"og:description\" content=\"Master Ruby Enumerable methods \u2014 each, map, and select \u2014 to write clean, efficient, and expressive Ruby code with better data handling.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.railscarma.com\/fr\/blog\/master-ruby-enumerable-each-map-and-select\/\" \/>\n<meta property=\"og:site_name\" content=\"RailsCarma - Ruby on Rails Development Company specializing in Offshore Development\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/RailsCarma\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-11-03T06:35:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-11-03T06:41:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2025\/11\/Master-Ruby-Enumerable-each-map-and-select.png\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"300\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"ashish\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@railscarma\" \/>\n<meta name=\"twitter:site\" content=\"@railscarma\" \/>\n<meta name=\"twitter:label1\" content=\"\u00c9crit par\" \/>\n\t<meta name=\"twitter:data1\" content=\"ashish\" \/>\n\t<meta name=\"twitter:label2\" content=\"Dur\u00e9e de lecture estim\u00e9e\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/\"},\"author\":{\"name\":\"ashish\",\"@id\":\"https:\/\/www.railscarma.com\/#\/schema\/person\/9699b14852b308edfeb03096b33c7a7a\"},\"headline\":\"Master Ruby Enumerable: each, map, and select\",\"datePublished\":\"2025-11-03T06:35:32+00:00\",\"dateModified\":\"2025-11-03T06:41:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/\"},\"wordCount\":447,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.railscarma.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2025\/11\/Master-Ruby-Enumerable-each-map-and-select.png\",\"articleSection\":[\"Blogs\"],\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/\",\"url\":\"https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/\",\"name\":\"Master Ruby Enumerable: each, map, and select - RailsCarma\",\"isPartOf\":{\"@id\":\"https:\/\/www.railscarma.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2025\/11\/Master-Ruby-Enumerable-each-map-and-select.png\",\"datePublished\":\"2025-11-03T06:35:32+00:00\",\"dateModified\":\"2025-11-03T06:41:24+00:00\",\"description\":\"Master Ruby Enumerable methods \u2014 each, map, and select \u2014 to write clean, efficient, and expressive Ruby code with better data handling.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/#breadcrumb\"},\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/#primaryimage\",\"url\":\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2025\/11\/Master-Ruby-Enumerable-each-map-and-select.png\",\"contentUrl\":\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2025\/11\/Master-Ruby-Enumerable-each-map-and-select.png\",\"width\":800,\"height\":300,\"caption\":\"Ruby Enumerable each, map, and select\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.railscarma.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Master Ruby Enumerable: each, map, and select\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.railscarma.com\/#website\",\"url\":\"https:\/\/www.railscarma.com\/\",\"name\":\"RailsCarma - Ruby on Rails Development Company specializing in Offshore Development\",\"description\":\"RailsCarma is a Ruby on Rails Development Company in Bangalore. We specialize in Offshore Ruby on Rails Development based out in USA and India. Hire experienced Ruby on Rails developers for the ultimate Web Experience.\",\"publisher\":{\"@id\":\"https:\/\/www.railscarma.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.railscarma.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"fr-FR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.railscarma.com\/#organization\",\"name\":\"RailsCarma\",\"url\":\"https:\/\/www.railscarma.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\/\/www.railscarma.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2020\/08\/railscarma_logo.png\",\"contentUrl\":\"https:\/\/www.railscarma.com\/wp-content\/uploads\/2020\/08\/railscarma_logo.png\",\"width\":200,\"height\":46,\"caption\":\"RailsCarma\"},\"image\":{\"@id\":\"https:\/\/www.railscarma.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/RailsCarma\/\",\"https:\/\/x.com\/railscarma\",\"https:\/\/www.linkedin.com\/company\/railscarma\/\",\"https:\/\/myspace.com\/railscarma\",\"https:\/\/in.pinterest.com\/railscarma\/\",\"https:\/\/www.youtube.com\/channel\/UCx3Wil-aAnDARuatTEyMdpg\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.railscarma.com\/#\/schema\/person\/9699b14852b308edfeb03096b33c7a7a\",\"name\":\"ashish\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\/\/www.railscarma.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/204411c7d72714bc32d5ac6398e0596896318386bd537860fdd14ce905a79e07?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/204411c7d72714bc32d5ac6398e0596896318386bd537860fdd14ce905a79e07?s=96&d=mm&r=g\",\"caption\":\"ashish\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Master Ruby Enumerable: each, map, and select - RailsCarma","description":"Master Ruby Enumerable methods \u2014 each, map, and select \u2014 to write clean, efficient, and expressive Ruby code with better data handling.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.railscarma.com\/fr\/blog\/master-ruby-enumerable-each-map-and-select\/","og_locale":"fr_FR","og_type":"article","og_title":"Master Ruby Enumerable: each, map, and select - RailsCarma","og_description":"Master Ruby Enumerable methods \u2014 each, map, and select \u2014 to write clean, efficient, and expressive Ruby code with better data handling.","og_url":"https:\/\/www.railscarma.com\/fr\/blog\/master-ruby-enumerable-each-map-and-select\/","og_site_name":"RailsCarma - Ruby on Rails Development Company specializing in Offshore Development","article_publisher":"https:\/\/www.facebook.com\/RailsCarma\/","article_published_time":"2025-11-03T06:35:32+00:00","article_modified_time":"2025-11-03T06:41:24+00:00","og_image":[{"width":800,"height":300,"url":"https:\/\/www.railscarma.com\/wp-content\/uploads\/2025\/11\/Master-Ruby-Enumerable-each-map-and-select.png","type":"image\/png"}],"author":"ashish","twitter_card":"summary_large_image","twitter_creator":"@railscarma","twitter_site":"@railscarma","twitter_misc":{"\u00c9crit par":"ashish","Dur\u00e9e de lecture estim\u00e9e":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/#article","isPartOf":{"@id":"https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/"},"author":{"name":"ashish","@id":"https:\/\/www.railscarma.com\/#\/schema\/person\/9699b14852b308edfeb03096b33c7a7a"},"headline":"Master Ruby Enumerable: each, map, and select","datePublished":"2025-11-03T06:35:32+00:00","dateModified":"2025-11-03T06:41:24+00:00","mainEntityOfPage":{"@id":"https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/"},"wordCount":447,"commentCount":0,"publisher":{"@id":"https:\/\/www.railscarma.com\/#organization"},"image":{"@id":"https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/#primaryimage"},"thumbnailUrl":"https:\/\/www.railscarma.com\/wp-content\/uploads\/2025\/11\/Master-Ruby-Enumerable-each-map-and-select.png","articleSection":["Blogs"],"inLanguage":"fr-FR","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/","url":"https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/","name":"Master Ruby Enumerable: each, map, and select - RailsCarma","isPartOf":{"@id":"https:\/\/www.railscarma.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/#primaryimage"},"image":{"@id":"https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/#primaryimage"},"thumbnailUrl":"https:\/\/www.railscarma.com\/wp-content\/uploads\/2025\/11\/Master-Ruby-Enumerable-each-map-and-select.png","datePublished":"2025-11-03T06:35:32+00:00","dateModified":"2025-11-03T06:41:24+00:00","description":"Master Ruby Enumerable methods \u2014 each, map, and select \u2014 to write clean, efficient, and expressive Ruby code with better data handling.","breadcrumb":{"@id":"https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/#breadcrumb"},"inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/"]}]},{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/#primaryimage","url":"https:\/\/www.railscarma.com\/wp-content\/uploads\/2025\/11\/Master-Ruby-Enumerable-each-map-and-select.png","contentUrl":"https:\/\/www.railscarma.com\/wp-content\/uploads\/2025\/11\/Master-Ruby-Enumerable-each-map-and-select.png","width":800,"height":300,"caption":"Ruby Enumerable each, map, and select"},{"@type":"BreadcrumbList","@id":"https:\/\/www.railscarma.com\/blog\/master-ruby-enumerable-each-map-and-select\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.railscarma.com\/"},{"@type":"ListItem","position":2,"name":"Master Ruby Enumerable: each, map, and select"}]},{"@type":"WebSite","@id":"https:\/\/www.railscarma.com\/#website","url":"https:\/\/www.railscarma.com\/","name":"RailsCarma - Soci\u00e9t\u00e9 de d\u00e9veloppement Ruby on Rails sp\u00e9cialis\u00e9e dans le d\u00e9veloppement offshore","description":"RailsCarma est une soci\u00e9t\u00e9 de d\u00e9veloppement Ruby on Rails \u00e0 Bangalore. Nous sommes sp\u00e9cialis\u00e9s dans le d\u00e9veloppement offshore Ruby on Rails, bas\u00e9s aux \u00c9tats-Unis et en Inde. Embauchez des d\u00e9veloppeurs Ruby on Rails exp\u00e9riment\u00e9s pour une exp\u00e9rience Web ultime.","publisher":{"@id":"https:\/\/www.railscarma.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.railscarma.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"fr-FR"},{"@type":"Organization","@id":"https:\/\/www.railscarma.com\/#organization","name":"RailsCarma","url":"https:\/\/www.railscarma.com\/","logo":{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/www.railscarma.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.railscarma.com\/wp-content\/uploads\/2020\/08\/railscarma_logo.png","contentUrl":"https:\/\/www.railscarma.com\/wp-content\/uploads\/2020\/08\/railscarma_logo.png","width":200,"height":46,"caption":"RailsCarma"},"image":{"@id":"https:\/\/www.railscarma.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/RailsCarma\/","https:\/\/x.com\/railscarma","https:\/\/www.linkedin.com\/company\/railscarma\/","https:\/\/myspace.com\/railscarma","https:\/\/in.pinterest.com\/railscarma\/","https:\/\/www.youtube.com\/channel\/UCx3Wil-aAnDARuatTEyMdpg"]},{"@type":"Person","@id":"https:\/\/www.railscarma.com\/#\/schema\/person\/9699b14852b308edfeb03096b33c7a7a","name":"ashish","image":{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/www.railscarma.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/204411c7d72714bc32d5ac6398e0596896318386bd537860fdd14ce905a79e07?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/204411c7d72714bc32d5ac6398e0596896318386bd537860fdd14ce905a79e07?s=96&d=mm&r=g","caption":"ashish"}}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.railscarma.com\/fr\/wp-json\/wp\/v2\/posts\/40261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.railscarma.com\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.railscarma.com\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.railscarma.com\/fr\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.railscarma.com\/fr\/wp-json\/wp\/v2\/comments?post=40261"}],"version-history":[{"count":0,"href":"https:\/\/www.railscarma.com\/fr\/wp-json\/wp\/v2\/posts\/40261\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.railscarma.com\/fr\/wp-json\/wp\/v2\/media\/40294"}],"wp:attachment":[{"href":"https:\/\/www.railscarma.com\/fr\/wp-json\/wp\/v2\/media?parent=40261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.railscarma.com\/fr\/wp-json\/wp\/v2\/categories?post=40261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.railscarma.com\/fr\/wp-json\/wp\/v2\/tags?post=40261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}