{"id":1786,"date":"2026-11-06T09:58:36","date_gmt":"2026-11-06T09:58:36","guid":{"rendered":"https:\/\/ruby-doc.org\/learn\/?p=1786"},"modified":"2026-11-06T09:58:37","modified_gmt":"2026-11-06T09:58:37","slug":"ruby-it-block-parameter","status":"publish","type":"post","link":"https:\/\/ruby-doc.org\/learn\/ruby-it-block-parameter\/","title":{"rendered":"Ruby it block parameter: Examples and Common Traps"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The Ruby it block parameter lets a block reference its argument without declaring a parameter name. Introduced with Ruby 3.4, the feature remains available in Ruby 4.0. It makes short transformations easier to read. Use a named parameter when the name indicates what the input represents, or when the block needs two or more arguments.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To take every number in a list and multiply it by two, you could use a named parameter, a numbered parameter, or the short version with no declared parameters. The following examples produce the same array. However, shorter code still requires knowing how methods pass arguments to blocks.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1600\" height=\"1180\" src=\"https:\/\/ruby-doc.org\/learn\/wp-content\/uploads\/2026\/11\/ruby-it-block-parameter-example.webp\" alt=\"Ruby it block parameter example: named and implicit doubling blocks turn 3, 5 and 8 into 6, 10 and 16\" class=\"wp-image-1785\" srcset=\"https:\/\/ruby-doc.org\/learn\/wp-content\/uploads\/2026\/11\/ruby-it-block-parameter-example.webp 1600w, https:\/\/ruby-doc.org\/learn\/wp-content\/uploads\/2026\/11\/ruby-it-block-parameter-example-300x221.webp 300w, https:\/\/ruby-doc.org\/learn\/wp-content\/uploads\/2026\/11\/ruby-it-block-parameter-example-1024x755.webp 1024w, https:\/\/ruby-doc.org\/learn\/wp-content\/uploads\/2026\/11\/ruby-it-block-parameter-example-768x566.webp 768w, https:\/\/ruby-doc.org\/learn\/wp-content\/uploads\/2026\/11\/ruby-it-block-parameter-example-1536x1133.webp 1536w\" sizes=\"auto, (max-width: 1600px) 100vw, 1600px\" \/><figcaption class=\"wp-element-caption\">A short doubling block can omit its explicit parameter name; the input values and resulting array remain the same.<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Ruby it block parameter syntax: a worked example<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Here we start out with three ticket quantities: three, five and eight. We map over these quantities, passing each into our block and collect up the results. Our block doubles each quantity generating us six, ten and sixteen. Our original array is intact.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>quantities = [3, 5, 8]\np quantities.map { |quantity| quantity * 2 }\np quantities.map { _1 * 2 }\np quantities.map { it * 2 }\n# Each line prints: [6, 10, 16]\np quantities\n# [3, 5, 8]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In the named version, declare the parameter between vertical bars before referencing it inside the expression. In the shorter version, Ruby supplies an implicit parameter. Remove the explicit declaration and replace its references in the body. Leaving the old declaration alone while changing the references is a different operation, with different consequences.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When reading a short doubling block, think of it as &#8220;double this&#8221;. There is only one possible input and one simple operation. For a block that calculates discounts, verifies if a person is eligible, and logs audit entries, give it a name like customer or order. While saving a couple of key strokes may be nice, you will lose the context.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Since this is native to Ruby, you will not need Rails, a gem or an import. But upgrading the interpreter in your terminal does not automatically change the interpreter used for tests or deployment. Check those environments separately before adopting the new syntax.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Named, numbered or method shorthand?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These four types are used to achieve somewhat different goals. Choose the one that will help the future developers most.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Form<\/th><th>Example<\/th><th>Useful when<\/th><\/tr><\/thead><tbody><tr><td>Named parameter<\/td><td><code>{ |quantity| quantity * 2 }<\/code><\/td><td>The name explains the input&#8217;s role.<\/td><\/tr><tr><td>Numbered parameter<\/td><td><code>{ _1 * 2 }<\/code><\/td><td>Position is clear from a short expression.<\/td><\/tr><tr><td>Implicit parameter<\/td><td><code>{ it * 2 }<\/code><\/td><td>There is one obvious input.<\/td><\/tr><tr><td>Symbol shorthand<\/td><td><code>map(&amp;:upcase)<\/code><\/td><td>Each item receives a simple method call.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">A named parameter adds information about an input and separates it from surrounding values. A numbered parameter uses position to identify an argument. The Ruby it block parameter is useful for a single obvious input. Meanwhile, symbols offer a compact way to send a simple method call to every item.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>labels = %w[red blue]\np labels.map(&amp;:upcase)\np labels.map { it.upcase }\n# Both lines print: [\"RED\", \"BLUE\"]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For instance, the symbol version easily converts a list of labels to UPPERCASE. If you have an additional argument, if you want to perform some calculations, or if you want to chain two method calls together then an ordinary block may provide a clearer view. It depends upon readability. This guide makes no claims about speed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Before you make changes, look at your project&#8217;s coding style guidelines. A change should comply with the existing code, and not create another style inside a function. Can the expression still stand up to scrutiny in context? Counting characters does not help determine that.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Ruby it block parameter: what reaches the block?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The Ruby it block parameter refers to an argument supplied by the yielding method. The argument need not be a plain value from a flat array. A nested array can arrive as a single object. Similarly, iterating through a hash can deliver an entry containing both the key and value.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Take two pairs of numbers. Let&#8217;s map them, but use the implicit parameter so they remain unchanged. If we wanted to add both numbers in a pair, we&#8217;d name both parts explicitly. Naming parts explicitly makes the calculation easier to understand. However, when doing a shortcut refactoring, you may end up altering something if you miss the objects being passed to the block.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It also comes down to what happens when a method yields multiple arguments. The small producer below yields two numbers. Its implicit parameter receives the first number. With two explicit parameters, however, the block can calculate a result from both. Check the method rather than assuming that the shorthand collects all its arguments.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>def provide_two\n  yield 4, 7\nend\np provide_two { it }\n# 4\np provide_two { |left, right| left + right }\n# 11<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To find out how Ruby handles implicit parameters, read the <a href=\"https:\/\/ruby-doc.org\/3.4.1\/Proc.html#class-Proc-label-it\">Ruby-Doc Proc reference on implicit parameters<\/a>. Also refer to your iterator\u2019s documentation: the method defines what it yields. Block syntax alone cannot tell you whether an input is a record, a pair, an index or separate objects.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Local names and mixed parameter styles<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Evaluate matching local variable names in the surrounding scope before using this shortcut. In the next sample, a local variable exists before the block executes. Therefore, each execution reads that variable instead of doubling an element of the original array. It is a scope issue, not a problem with the multiplication.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>it = 9\np [1, 2].map { it * 2 }\n# [18, 18]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">While this is legitimate Ruby (and even though it can be confusing as to whether you are reading duplicate values), provide clarity through naming of surrounding variables or continue with explicit parameter declaration. Avoid making sweeping searches and replacing all occurrences without evaluating their intent.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ruby forbids combining numbered parameters and the new implicit parameter in one block. Using the implicit name alongside an explicit parameter declaration also raises a syntax error when no existing local name or method resolves it. Choose one parameter style for the block and keep all its references consistent.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Intentionally invalid; each expression raises SyntaxError:\n[1, 2].map { _1 + it }\n[1, 2].map { |value| it * 2 }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A syntax error indicates investigation into declarations and references of the block. An unexpected output also merits investigating the referenced objects and the surrounding scope. Gems do nothing to address either issue since they are related to Ruby&#8217;s language rules.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Nested blocks: name the values you need<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Ruby allows nested implicit blocks. Each inner block gets its own implicit parameter, so the same word can refer to different values nearby. These simple operations remain manageable while they are trivial. Once a calculation involves values from both levels, the scope becomes harder to follow.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Assume you wish to multiply some base quantities by various multipliers. Use meaningful labels for the outer quantity. Then use the abbreviated parameter for the inner multiplier provided that your expression is understandable. The labeled quantity remains accessible in the inner block while the multiplication demonstrates what was used in calculating it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>p [2, 3].map { |base| [10, 20].map { base * it } }\n# [[20, 40], [30, 60]]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If both levels utilize implicit parameters, however, the inner reference does not extend to the outer argument. A reviewer should never have to identify scopes to determine a basic arithmetic calculation. It would be reasonable to assign both parameters names regardless of whether your block becomes larger than expected.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Try the Ruby it block parameter exercise<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Decide what result you expect before reading the solution. Both expressions map over the same pairs. One returns each pair as provided; the other names the two elements and adds them. Will these produce equivalent arrays? Or will one maintain the nested structure?<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pairs = [[2, 3], [4, 5]]\np pairs.map { it }\np pairs.map { |left, right| left + right }<\/code><\/pre>\n\n\n\n<details class=\"wp-block-details is-layout-flow wp-block-details-is-layout-flow\"><summary>Reveal the two results and why they differ<\/summary>\n\n\n<pre class=\"wp-block-code\"><code>[[2, 3], [4, 5]]\n[5, 9]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The results differ. One maintains each pair as an item in its output array. The other sums both components and returns an array of totals. Parameter handling and the expressions inside the blocks account for the difference. No flattening operation is applied.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Modify a pair or add another pair. Before you run the code again, describe what you predict will happen. If you only want to have access to one value per pair, specify that explicitly. As with anything else, a few iterations of this type of process will help you feel confident about shortening an iteration in actual application code.<\/p>\n\n\n<\/details>\n\n\n\n<h2 class=\"wp-block-heading\">Choose a team policy and check the runtime<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/docs.rubocop.org\/rubocop\/latest\/cops_style.html#styleitblockparameter\">RuboCop\u2019s block-parameter style rule<\/a> offers options to allow single-line use of the shorthand or disallow it altogether. This rule requires a Ruby 3.4 target. Teams can therefore define their conventions instead of accepting all proposed stylistic changes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Consider editor support too. <a href=\"https:\/\/blog.jetbrains.com\/ruby\/2024\/11\/rubymine-2024-3-rails-8-support\/\">JetBrains documented RubyMine 2024.3 support<\/a> for recognizing and converting this parameter. If an editor flags valid syntax, check its language support and selected interpreter before editing working code. A suggested edit does not prove what happens at runtime.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">First, determine the minimum Ruby version across all your application\u2019s supported environments. After that, take a simple, obvious block and find out where it fits into its local scope. Then run the relevant tests to see if your results (and side effects) remain identical to the original. Use named parameters whenever they aid in describing a role in the domain or differentiate multiple inputs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The executable examples above were checked with native Ruby 4.0.0 on Linux. This establishes the demonstrated results for that runtime, not execution on Ruby 3.4 or every subsequent patch. The intentionally invalid expressions were checked for syntax errors. No performance measurements are included; your application needs its own tests.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Takeaway<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use the Ruby it block parameter when one apparent input makes a brief expression understandable. Before replacing explicit parameters, look at the yielded objects and surrounding local variables. Several inputs, nested computations or domain roles may need more explanation. In those cases, descriptive names convey more than a shorter block.<\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>Learn when Ruby&#8217;s implicit it parameter helps, how local names and nested blocks affect it, and when a named parameter is clearer.<\/p>\n","protected":false},"author":3,"featured_media":1785,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1786","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ruby-tips"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":7}},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Ruby it block parameter: Examples and Common Traps<\/title>\n<meta name=\"description\" content=\"Use the Ruby it block parameter with clear examples, scope traps, named-parameter comparisons and a practical exercise for Ruby 3.4 and later.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ruby-doc.org\/learn\/ruby-it-block-parameter\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Ruby it block parameter: Examples and Common Traps\" \/>\n<meta property=\"og:description\" content=\"Use the Ruby it block parameter with clear examples, scope traps, named-parameter comparisons and a practical exercise for Ruby 3.4 and later.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ruby-doc.org\/learn\/ruby-it-block-parameter\/\" \/>\n<meta property=\"og:site_name\" content=\"Ruby-Doc Learn\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-06T09:58:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-06T09:58:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ruby-doc.org\/learn\/wp-content\/uploads\/2026\/11\/ruby-it-block-parameter-example.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1600\" \/>\n\t<meta property=\"og:image:height\" content=\"1180\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"James Britt\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Britt\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/ruby-it-block-parameter\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/ruby-it-block-parameter\\\/\"},\"author\":{\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/james-britt\\\/#james-britt\"},\"headline\":\"Ruby it block parameter: Examples and Common Traps\",\"datePublished\":\"2026-11-06T09:58:36+00:00\",\"dateModified\":\"2026-11-06T09:58:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/ruby-it-block-parameter\\\/\"},\"wordCount\":1527,\"publisher\":{\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/ruby-it-block-parameter\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/ruby-it-block-parameter-example.webp\",\"articleSection\":[\"Ruby tips\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/ruby-it-block-parameter\\\/\",\"url\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/ruby-it-block-parameter\\\/\",\"name\":\"Ruby it block parameter: Examples and Common Traps\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/ruby-it-block-parameter\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/ruby-it-block-parameter\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/ruby-it-block-parameter-example.webp\",\"datePublished\":\"2026-11-06T09:58:36+00:00\",\"dateModified\":\"2026-11-06T09:58:37+00:00\",\"description\":\"Use the Ruby it block parameter with clear examples, scope traps, named-parameter comparisons and a practical exercise for Ruby 3.4 and later.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/ruby-it-block-parameter\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/ruby-it-block-parameter\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/ruby-it-block-parameter\\\/#primaryimage\",\"url\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/ruby-it-block-parameter-example.webp\",\"contentUrl\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/ruby-it-block-parameter-example.webp\",\"width\":1600,\"height\":1180,\"caption\":\"A short doubling block can omit its explicit parameter name; the input values and resulting array remain the same.\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/ruby-it-block-parameter\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Ruby it block parameter: Examples and Common Traps\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/#website\",\"url\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/\",\"name\":\"Ruby-Doc Learn\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/#organization\",\"name\":\"Ruby-Doc Learn\",\"url\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/ruby-doc-logo-transparent.png\",\"contentUrl\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/ruby-doc-logo-transparent.png\",\"width\":1650,\"height\":305,\"caption\":\"Ruby-Doc Learn\"},\"image\":{\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/james-britt\\\/#james-britt\",\"name\":\"James Britt\",\"image\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/wp-content\\\/uploads\\\/2026\\\/09\\\/jgb_self-portrait-20140914.png\",\"description\":\"Creator and long-term maintainer of Ruby-Doc.org, founder of Neurogami, and author of practical Ruby tutorials for Ruby-Doc Learn.\",\"sameAs\":[\"https:\\\/\\\/jamesbritt.com\\\/\",\"https:\\\/\\\/neurogami.com\\\/\",\"https:\\\/\\\/www.oreilly.com\\\/pub\\\/au\\\/2595\",\"https:\\\/\\\/www.rubyevents.org\\\/profiles\\\/james-britt\"],\"url\":\"https:\\\/\\\/ruby-doc.org\\\/learn\\\/james-britt\\\/\",\"jobTitle\":\"Ruby developer and writer\",\"knowsAbout\":[\"Ruby programming language\",\"Ruby documentation\",\"JRuby\",\"Open Sound Control\",\"Software development\"],\"affiliation\":{\"@type\":\"Organization\",\"name\":\"Ruby-Doc.org\",\"url\":\"https:\\\/\\\/ruby-doc.org\\\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Ruby it block parameter: Examples and Common Traps","description":"Use the Ruby it block parameter with clear examples, scope traps, named-parameter comparisons and a practical exercise for Ruby 3.4 and later.","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:\/\/ruby-doc.org\/learn\/ruby-it-block-parameter\/","og_locale":"en_US","og_type":"article","og_title":"Ruby it block parameter: Examples and Common Traps","og_description":"Use the Ruby it block parameter with clear examples, scope traps, named-parameter comparisons and a practical exercise for Ruby 3.4 and later.","og_url":"https:\/\/ruby-doc.org\/learn\/ruby-it-block-parameter\/","og_site_name":"Ruby-Doc Learn","article_published_time":"2026-11-06T09:58:36+00:00","article_modified_time":"2026-11-06T09:58:37+00:00","og_image":[{"width":1600,"height":1180,"url":"https:\/\/ruby-doc.org\/learn\/wp-content\/uploads\/2026\/11\/ruby-it-block-parameter-example.webp","type":"image\/webp"}],"author":"James Britt","twitter_card":"summary_large_image","twitter_misc":{"Written by":"James Britt","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ruby-doc.org\/learn\/ruby-it-block-parameter\/#article","isPartOf":{"@id":"https:\/\/ruby-doc.org\/learn\/ruby-it-block-parameter\/"},"author":{"@id":"https:\/\/ruby-doc.org\/learn\/james-britt\/#james-britt"},"headline":"Ruby it block parameter: Examples and Common Traps","datePublished":"2026-11-06T09:58:36+00:00","dateModified":"2026-11-06T09:58:37+00:00","mainEntityOfPage":{"@id":"https:\/\/ruby-doc.org\/learn\/ruby-it-block-parameter\/"},"wordCount":1527,"publisher":{"@id":"https:\/\/ruby-doc.org\/learn\/#organization"},"image":{"@id":"https:\/\/ruby-doc.org\/learn\/ruby-it-block-parameter\/#primaryimage"},"thumbnailUrl":"https:\/\/ruby-doc.org\/learn\/wp-content\/uploads\/2026\/11\/ruby-it-block-parameter-example.webp","articleSection":["Ruby tips"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/ruby-doc.org\/learn\/ruby-it-block-parameter\/","url":"https:\/\/ruby-doc.org\/learn\/ruby-it-block-parameter\/","name":"Ruby it block parameter: Examples and Common Traps","isPartOf":{"@id":"https:\/\/ruby-doc.org\/learn\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ruby-doc.org\/learn\/ruby-it-block-parameter\/#primaryimage"},"image":{"@id":"https:\/\/ruby-doc.org\/learn\/ruby-it-block-parameter\/#primaryimage"},"thumbnailUrl":"https:\/\/ruby-doc.org\/learn\/wp-content\/uploads\/2026\/11\/ruby-it-block-parameter-example.webp","datePublished":"2026-11-06T09:58:36+00:00","dateModified":"2026-11-06T09:58:37+00:00","description":"Use the Ruby it block parameter with clear examples, scope traps, named-parameter comparisons and a practical exercise for Ruby 3.4 and later.","breadcrumb":{"@id":"https:\/\/ruby-doc.org\/learn\/ruby-it-block-parameter\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ruby-doc.org\/learn\/ruby-it-block-parameter\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ruby-doc.org\/learn\/ruby-it-block-parameter\/#primaryimage","url":"https:\/\/ruby-doc.org\/learn\/wp-content\/uploads\/2026\/11\/ruby-it-block-parameter-example.webp","contentUrl":"https:\/\/ruby-doc.org\/learn\/wp-content\/uploads\/2026\/11\/ruby-it-block-parameter-example.webp","width":1600,"height":1180,"caption":"A short doubling block can omit its explicit parameter name; the input values and resulting array remain the same."},{"@type":"BreadcrumbList","@id":"https:\/\/ruby-doc.org\/learn\/ruby-it-block-parameter\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ruby-doc.org\/learn\/"},{"@type":"ListItem","position":2,"name":"Ruby it block parameter: Examples and Common Traps"}]},{"@type":"WebSite","@id":"https:\/\/ruby-doc.org\/learn\/#website","url":"https:\/\/ruby-doc.org\/learn\/","name":"Ruby-Doc Learn","description":"","publisher":{"@id":"https:\/\/ruby-doc.org\/learn\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ruby-doc.org\/learn\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/ruby-doc.org\/learn\/#organization","name":"Ruby-Doc Learn","url":"https:\/\/ruby-doc.org\/learn\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ruby-doc.org\/learn\/#\/schema\/logo\/image\/","url":"https:\/\/ruby-doc.org\/learn\/wp-content\/uploads\/2026\/09\/ruby-doc-logo-transparent.png","contentUrl":"https:\/\/ruby-doc.org\/learn\/wp-content\/uploads\/2026\/09\/ruby-doc-logo-transparent.png","width":1650,"height":305,"caption":"Ruby-Doc Learn"},"image":{"@id":"https:\/\/ruby-doc.org\/learn\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/ruby-doc.org\/learn\/james-britt\/#james-britt","name":"James Britt","image":"https:\/\/ruby-doc.org\/learn\/wp-content\/uploads\/2026\/09\/jgb_self-portrait-20140914.png","description":"Creator and long-term maintainer of Ruby-Doc.org, founder of Neurogami, and author of practical Ruby tutorials for Ruby-Doc Learn.","sameAs":["https:\/\/jamesbritt.com\/","https:\/\/neurogami.com\/","https:\/\/www.oreilly.com\/pub\/au\/2595","https:\/\/www.rubyevents.org\/profiles\/james-britt"],"url":"https:\/\/ruby-doc.org\/learn\/james-britt\/","jobTitle":"Ruby developer and writer","knowsAbout":["Ruby programming language","Ruby documentation","JRuby","Open Sound Control","Software development"],"affiliation":{"@type":"Organization","name":"Ruby-Doc.org","url":"https:\/\/ruby-doc.org\/"}}]}},"_links":{"self":[{"href":"https:\/\/ruby-doc.org\/learn\/wp-json\/wp\/v2\/posts\/1786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ruby-doc.org\/learn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ruby-doc.org\/learn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ruby-doc.org\/learn\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/ruby-doc.org\/learn\/wp-json\/wp\/v2\/comments?post=1786"}],"version-history":[{"count":1,"href":"https:\/\/ruby-doc.org\/learn\/wp-json\/wp\/v2\/posts\/1786\/revisions"}],"predecessor-version":[{"id":1787,"href":"https:\/\/ruby-doc.org\/learn\/wp-json\/wp\/v2\/posts\/1786\/revisions\/1787"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ruby-doc.org\/learn\/wp-json\/wp\/v2\/media\/1785"}],"wp:attachment":[{"href":"https:\/\/ruby-doc.org\/learn\/wp-json\/wp\/v2\/media?parent=1786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ruby-doc.org\/learn\/wp-json\/wp\/v2\/categories?post=1786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ruby-doc.org\/learn\/wp-json\/wp\/v2\/tags?post=1786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}