File tree Expand file tree Collapse file tree 1 file changed +24
-24
lines changed Expand file tree Collapse file tree 1 file changed +24
-24
lines changed Original file line number Diff line number Diff 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]]
You can’t perform that action at this time.
0 commit comments