Skip to content

Commit 41fb457

Browse files
committed
Up
1 parent 1bd8ce5 commit 41fb457

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

README.adoc

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4307,30 +4307,30 @@ other keys that have not been explicitly assigned to.
43074307

43084308
[source,ruby]
43094309
----
4310-
# bad
4311-
Hash.new([])
4312-
Hash.new({})
4313-
Hash.new(Array.new)
4314-
Hash.new(Hash.new)
4315-
4316-
# okay -- beware this will silently discard mutations and only remember assignments
4317-
Hash.new { Array.new }
4318-
Hash.new { Hash.new }
4319-
Hash.new { {} }
4320-
Hash.new { [] }
4321-
4322-
# good - frozen solution will raise an error when mutation is attempted
4323-
Hash.new([].freeze)
4324-
Hash.new({}.freeze)
4325-
4326-
# good - using a proc will create a new object for each key
4327-
h = Hash.new
4328-
h.default_proc = ->(h, k) { [] }
4329-
h.default_proc = ->(h, k) { {} }
4330-
4331-
# good - using a block will create a new object for each key
4332-
Hash.new { |h, k| h[k] = [] }
4333-
Hash.new { |h, k| h[k] = {} }
4310+
# bad
4311+
Hash.new([])
4312+
Hash.new({})
4313+
Hash.new(Array.new)
4314+
Hash.new(Hash.new)
4315+
4316+
# okay -- beware this will silently discard mutations and only remember assignments
4317+
Hash.new { Array.new }
4318+
Hash.new { Hash.new }
4319+
Hash.new { {} }
4320+
Hash.new { [] }
4321+
4322+
# good - frozen solution will raise an error when mutation is attempted
4323+
Hash.new([].freeze)
4324+
Hash.new({}.freeze)
4325+
4326+
# good - using a proc will create a new object for each key
4327+
h = Hash.new
4328+
h.default_proc = ->(h, k) { [] }
4329+
h.default_proc = ->(h, k) { {} }
4330+
4331+
# good - using a block will create a new object for each key
4332+
Hash.new { |h, k| h[k] = [] }
4333+
Hash.new { |h, k| h[k] = {} }
43344334
----
43354335

43364336
=== Hash Literals [[hash-literals]]

0 commit comments

Comments
 (0)