[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"detail-sidebar-cat-0-en-105":3,"doc-seo-673336-105":59,"doc-detail-673336-en":129},{"code":4,"msg":5,"data":6},0,"success",[7,13,18,23,28,33,38,43,48,51,55],{"id":8,"doc_module":4,"doc_module_name":9,"category_name":10,"show_sort_weight":11,"slug":12},1,"Document","Story & Novel",90,"story-novel",{"id":14,"doc_module":4,"doc_module_name":9,"category_name":15,"show_sort_weight":16,"slug":17},2,"Literature",80,"literature",{"id":19,"doc_module":4,"doc_module_name":9,"category_name":20,"show_sort_weight":21,"slug":22},4,"Exam",70,"exam",{"id":24,"doc_module":4,"doc_module_name":9,"category_name":25,"show_sort_weight":26,"slug":27},5,"Comic",60,"comic",{"id":29,"doc_module":4,"doc_module_name":9,"category_name":30,"show_sort_weight":31,"slug":32},6,"Technology",50,"technology",{"id":34,"doc_module":4,"doc_module_name":9,"category_name":35,"show_sort_weight":36,"slug":37},7,"Healthcare",40,"healthcare",{"id":39,"doc_module":4,"doc_module_name":9,"category_name":40,"show_sort_weight":41,"slug":42},8,"Research & Report",30,"research-report",{"id":44,"doc_module":4,"doc_module_name":9,"category_name":45,"show_sort_weight":46,"slug":47},9,"Religion & Spirituality",20,"religion-spirituality",{"id":46,"doc_module":4,"doc_module_name":9,"category_name":49,"show_sort_weight":46,"slug":50},"World Cup","world-cup",{"id":52,"doc_module":4,"doc_module_name":9,"category_name":53,"show_sort_weight":52,"slug":54},10,"Lifestyle","lifestyle",{"id":56,"doc_module":4,"doc_module_name":9,"category_name":57,"show_sort_weight":24,"slug":58},19,"General","general",{"code":4,"msg":60,"data":61},"ok",{"site_id":62,"language":63,"slug":64,"title":65,"keywords":66,"description":67,"schema_data":68,"social_meta":122,"head_meta":124,"extra_data":126,"updated_unix":128},105,"en","each-vs-map-vs-select-when-to-use-ruby-enumerable-methods","Each vs Map vs Select - When to Use Ruby Enumerable Methods","","Guide explains how to choose between Ruby Enumerable methods each, select, and map when working with collections like Array and Hash. It walks through each as the basic iterator and building block, then shows select as a filter that builds a new array of matching elements, and map as a transformer that returns a new array of per-element results. The guide compares efficiency, typical use cases, and what each method returns, ending with practice exercises.",{"@graph":69,"@context":121},[70,84,104],{"@type":71,"itemListElement":72},"BreadcrumbList",[73,77,79,82],{"item":74,"name":75,"@type":76,"position":8},"https://docshare.wps.com","Home","ListItem",{"item":78,"name":9,"@type":76,"position":14},"https://docshare.wps.com/document/",{"item":80,"name":30,"@type":76,"position":81},"https://docshare.wps.com/document/technology/",3,{"item":83,"name":65,"@type":76,"position":19},"https://docshare.wps.com/document/each-vs-map-vs-select-when-to-use-ruby-enumerable-methods/673336/",{"url":83,"name":65,"@type":85,"image":86,"author":91,"headline":65,"publisher":94,"fileFormat":97,"inLanguage":63,"description":67,"dateModified":98,"datePublished":98,"encodingFormat":97,"isAccessibleForFree":99,"interactionStatistic":100},"DigitalDocument",{"url":87,"@type":88,"width":89,"height":90},"https://docshare.wps.com/thumbnails/each-vs-map-vs-select-when-to-use-ruby-enumerable-methods/673336.png","ImageObject",300,407,{"name":92,"@type":93},"Levi","Person",{"url":74,"name":95,"@type":96},"DocShare","Organization","application/pdf","2026-11-02",true,{"@type":101,"interactionType":102,"userInteractionCount":8},"InteractionCounter",{"@type":103},"ViewAction",{"@type":105,"mainEntity":106},"FAQPage",[107,113,117],{"name":108,"@type":109,"acceptedAnswer":110},"What is the purpose of Ruby's each method?","Question",{"text":111,"@type":112},"each iterates over a collection and is the basic Enumerable building block. It commonly acts like a standard loop, and you can use each_with_index when you need indices.","Answer",{"name":114,"@type":109,"acceptedAnswer":115},"How does select differ from each?",{"text":116,"@type":112},"select filters elements that match a condition and returns a new array containing only the matching items. With each, you would need extra code such as an accumulator array and an if statement to achieve the same result.",{"name":118,"@type":109,"acceptedAnswer":119},"What does map return, and how should you use its results?",{"text":120,"@type":112},"map transforms every element and returns a new array of the transformed results without changing the original array. To keep the results, assign the return value to a variable.","https://schema.org",{"og:url":83,"og:type":123,"og:title":65,"og:site_name":95,"og:description":67},"article",{"robots":125,"canonical":83},"index,follow",{"doc_id":127,"site_id":62},673336,1793630686,{"code":4,"msg":5,"data":130},{"doc_id":127,"user_id":131,"nickname":92,"user_avatar":132,"doc_module":4,"category_id":29,"category_name":30,"doc_title":65,"doc_description":67,"doc_content":133,"file_id":134,"file_url":135,"file_type":136,"file_size":137,"view_count":8,"is_deleted":4,"is_public":8,"is_downloadable":8,"audit_status":8,"page_count":34,"language":138,"language_code":63,"site_id":62,"html_lang":63,"table_of_contents":139,"faqs":140,"seo_title":141,"seo_description":67,"update_tm":128,"read_time":142},7971461740909,"https://ap-avatar.wpscdn.com/davatar_155a257f0dc6eb9ab79c44ca47cae57d","Each vs Map vs Select  \n\n|  |\n| --- |\n| These 3 methods (each, map & select) are the most important Ruby methods that you need to know.\u003Cbr>Why?\u003Cbr>Because a lot of what you are going to be doing is working with data.\u003Cbr>And these methods are used to work with collections of data (Array, Hash, Range) .\u003Cbr>In this guide I want to help you understand the difference between these methods & when you should be using one or the other. |\n\nThe Each Method  \n\n|  |\n| --- |\n| Each is the most basic of the Enumerable methods.\u003Cbr>In fact, almost every other method that iterates over a collection is based on each.\u003Cbr>So it's like a building block.\u003Cbr>Let's see an example: |\n| \u003Cbr>numbers = [ 1 , 2 , 3 ]\u003Cbr>numbers .each { | n | puts n }\u003Cbr>\\# 1\u003Cbr>\\# 2\u003Cbr>\\# 3 |\n| This is your basic loop in Ruby (if you need the index you can use each_with_index) .\u003Cbr>But many times you want to do something more than just print the elements. . .\u003Cbr>That's where the other methods come into play. |\n\nThe Select Method  \n\n|  |\n| --- |\n| Select & Map are specialized versions of each.\u003Cbr>With select you can \"filter\" your array to create a new array with only the matching elements.\u003Cbr>Example: |\n| \u003Cbr>numbers = [ 1 , 2 , 3 ,4 , 5 , 6 ]\u003Cbr>[numbers.](numbers. select { |n|)[ select](numbers. select { |n|)[ {](numbers. select { |n|)[ |](numbers. select { |n|)[n](numbers. select { |n|)[|](numbers. select { |n|) n.even? }\u003Cbr>\\# [ 2 ,4 , 6 ] |\n| In this example we filter our original numbers to only the numbers that are even.\u003Cbr>We can still do this with the each method, but it will require some extra code.\u003Cbr>Example: |\n| \u003Cbr>numbers = [ 1 , 2 , 3 ,4 , 5 , 6 ] results = []\u003Cbr>numbers .each { | n | results \u003C\u003C n if numbers .even? }\u003Cbr>p results\u003Cbr>\\# [ 2 ,4 , 6 ] |\n| Notice how we need a few extra elements:\u003Cbr> An empty array to store our results\u003Cbr> The \u003C\u003C (called \"shovel\" or \"push \" operator) , which appends a new value into the results array\u003Cbr> An if statement\u003Cbr>All of these things are taken care for us by Ruby when we use select instead of each.\u003Cbr>That's what I mean with \"a more specialized version of each \" . |\n\nThe Map Method  \n\n|  |\n| --- |\n| The map method helps you collect the results of iterating over your array elements, resulting in a new array.\u003Cbr>It can be used to apply some operation, like downcase or upcase, to every element of the array.\u003Cbr>Example: |\n| \u003Cbr>names = [ \"David \" , \"Grant \" , \"Bob \" ] [names.](names.map { |name|)[map](names.map { |name|)[ {](names.map { |name|)[ |](names.map { |name|)[name](names.map { |name|)[|](names.map { |name|) name.downcase }\u003Cbr>\\# [ \"david \" , \"grant \" , \" bob \" ] |\n| Notice that this doesn 't change the original array! It returns a new one. If you want to save the results of map you need to use a variable.\u003Cbr>Like this: |\n| \u003Cbr>[downcase_names](downcase_names = names.map { |name|)[ =](downcase_names = names.map { |name|)[ names.](downcase_names = names.map { |name|)[map](downcase_names = names.map { |name|)[ {](downcase_names = names.map { |name|)[ |](downcase_names = names.map { |name|)[name](downcase_names = names.map { |name|)[|](downcase_names = names.map { |name|) name.downcase } |\n| You can also use map for numbers or anything else: |\n| \u003Cbr>numbers = [ 1 , 2 , 3 ,4 , 5 ] [numbers.](numbers.map { |n|)[map](numbers.map { |n|)[ {](numbers.map { |n|)[ |](numbers.map { |n|)[n](numbers.map { |n|)[|](numbers.map { |n|) n * 10 }\u003Cbr>\\# [ 10 , 20 , 30 , 40 , 50] |\n| Don 't just read this. Open irb now & practice using map : ) |\n\nThe Difference  \n\n|  |\n| --- |\n| Ok so what is the difference between these?\u003Cbr>Besides each, every Enumerable method has it's own specialized function.\u003Cbr>Refer to the Ruby documentation to learn what every method does & to see examples.\u003Cbr>(Note: Enumerable is a built-in Ruby module that hosts these methods)\u003Cbr>You should always use the more specialized methods if possible because they are more efficient & produce better code.\u003Cbr>If you can 't find the perfect method for your situation rememb","cbCaimqSeZHQdrYe","https://ap.wps.com/l/cbCaimqSeZHQdrYe","pdf",110823,"English","# The Each Method\n# The Select Method\n# The Map Method\n# The Difference\n# Summary","[{\"question\":\"What is the purpose of Ruby's each method?\",\"answer\":\"each iterates over a collection and is the basic Enumerable building block. It commonly acts like a standard loop, and you can use each_with_index when you need indices.\"},{\"question\":\"How does select differ from each?\",\"answer\":\"select filters elements that match a condition and returns a new array containing only the matching items. With each, you would need extra code such as an accumulator array and an if statement to achieve the same result.\"},{\"question\":\"What does map return, and how should you use its results?\",\"answer\":\"map transforms every element and returns a new array of the transformed results without changing the original array. To keep the results, assign the return value to a variable.\"}]","Each vs Map vs Select - When to Use Ruby Enumerable Methods | PDF",18]