Skip to content

Fix Hash.new(initial_capacity, &block) doc to use relevant example#14429

Merged
straight-shoota merged 1 commit intocrystal-lang:masterfrom
lachlan:fix_hash_new_capacity_block_doco
Apr 5, 2024
Merged

Fix Hash.new(initial_capacity, &block) doc to use relevant example#14429
straight-shoota merged 1 commit intocrystal-lang:masterfrom
lachlan:fix_hash_new_capacity_block_doco

Conversation

@lachlan
Copy link
Contributor

@lachlan lachlan commented Apr 4, 2024

The Hash.new(initial_capacity = nil, &block : Hash(K, V), K -> V) comment's first code example calls a different constructor rather than the constructor being documented:

inventory = Hash(String, Int32).new(0) # => actually calls Hash.new(default_value : V, initial_capacity = nil)
inventory["socks"] = 3
inventory["pickles"] # => 0

Fixed to provide an example of how to use the Hash.new(initial_capacity = nil, &block : Hash(K, V), K -> V) constructor instead.

@straight-shoota straight-shoota merged commit dbf7aef into crystal-lang:master Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants