From d821924dd88e06cad85f59da5080b82d380e3008 Mon Sep 17 00:00:00 2001 From: Bijay Shrestha Date: Mon, 6 Oct 2025 10:54:52 +0545 Subject: [PATCH 1/4] Clarify independence of inner arrays in nested collections example --- ruby/basic_ruby/nested_collections.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ruby/basic_ruby/nested_collections.md b/ruby/basic_ruby/nested_collections.md index cc2d78e02d3..cf3de4cfe04 100644 --- a/ruby/basic_ruby/nested_collections.md +++ b/ruby/basic_ruby/nested_collections.md @@ -110,6 +110,8 @@ immutable #=> [[1000, nil], [nil, nil], [nil, nil]] ``` +Each `{ Array.new(2) }` block creates a new inner array. This means all three inner arrays are **independent objects**. When you modify one, the others stay the same. + Changing the value of the first element in the first nested array does not cause the value to change in any other nested array. ### Adding and removing elements From 1c4c5fad74c5e15c619d70244ffb6e1a5cf6ef2b Mon Sep 17 00:00:00 2001 From: Bijay Shrestha Date: Tue, 7 Oct 2025 12:58:28 +0545 Subject: [PATCH 2/4] Rename variable for clarity in immutable nested arrays example --- ruby/basic_ruby/nested_collections.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ruby/basic_ruby/nested_collections.md b/ruby/basic_ruby/nested_collections.md index cf3de4cfe04..6dcfbd4bee0 100644 --- a/ruby/basic_ruby/nested_collections.md +++ b/ruby/basic_ruby/nested_collections.md @@ -102,11 +102,11 @@ Changing the value of the first element in the first nested array, causes the fi Now, let's take a look at an example that omits the second optional argument and instead passes in the mutable value in a block. ```ruby -immutable = Array.new(3) { Array.new(2) } +nested_arrays = Array.new(3) { Array.new(2) } #=> [[nil, nil], [nil, nil], [nil, nil]] -immutable[0][0] = 1000 +nested_arrays[0][0] = 1000 #=> 1000 -immutable +nested_arrays #=> [[1000, nil], [nil, nil], [nil, nil]] ``` From 38555add6dee8f01e89b2d00fa0374ec5c19d99e Mon Sep 17 00:00:00 2001 From: Bijay Shrestha Date: Thu, 9 Oct 2025 13:17:54 +0545 Subject: [PATCH 3/4] Clarify section heading for creating nested arrays in mutable context --- ruby/basic_ruby/nested_collections.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ruby/basic_ruby/nested_collections.md b/ruby/basic_ruby/nested_collections.md index 6dcfbd4bee0..74b6c42f923 100644 --- a/ruby/basic_ruby/nested_collections.md +++ b/ruby/basic_ruby/nested_collections.md @@ -99,7 +99,7 @@ mutable Changing the value of the first element in the first nested array, causes the first element to change in all three nested arrays! This same behavior will happen with strings, hashes, or any other mutable objects. -Now, let's take a look at an example that omits the second optional argument and instead passes in the mutable value in a block. +Now, let's take a look at an example that omits the second optional argument and instead passes in the mutable value in a block. ```ruby nested_arrays = Array.new(3) { Array.new(2) } @@ -354,7 +354,7 @@ The following questions are an opportunity to reflect on key topics in this less - [How do you add data to a nested hash?](#adding-and-removing-data) - [How do you delete elements from a nested array?](#remove-elements-nested-array) - [How do you delete data in a nested hash?](#deleting-data-nested-hash) -- [How do you create a new nested array that is not mutable?](#create-immutable-nested-arrays) +- [How do you create a new nested array that is not mutable?](#create-nested-arrays) - [How do you iterate over a nested array?](#iterating-over-a-nested-array) - [How do you iterate over a nested hash?](#methods) From 1926ef7fddd6ffdbc60d2298c7304c694af11ac8 Mon Sep 17 00:00:00 2001 From: Bijay Shrestha Date: Thu, 9 Oct 2025 17:39:20 +0545 Subject: [PATCH 4/4] Clarify wording for creating non-mutable nested arrays --- ruby/basic_ruby/nested_collections.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby/basic_ruby/nested_collections.md b/ruby/basic_ruby/nested_collections.md index 74b6c42f923..a86879d348f 100644 --- a/ruby/basic_ruby/nested_collections.md +++ b/ruby/basic_ruby/nested_collections.md @@ -354,7 +354,7 @@ The following questions are an opportunity to reflect on key topics in this less - [How do you add data to a nested hash?](#adding-and-removing-data) - [How do you delete elements from a nested array?](#remove-elements-nested-array) - [How do you delete data in a nested hash?](#deleting-data-nested-hash) -- [How do you create a new nested array that is not mutable?](#create-nested-arrays) +- [How do you create a new nested array that can’t be changed through references to the original one?](#create-nested-arrays) - [How do you iterate over a nested array?](#iterating-over-a-nested-array) - [How do you iterate over a nested hash?](#methods)