Project

General

Profile

Actions

Bug #2764

closed

Hash.new inconsistency when initialized with an enumerable

Added by florent (Florent Vaucelle) about 14 years ago. Updated about 13 years ago.

Status:
Rejected
Assignee:
-
ruby -v:
ruby 1.8.7 (2009-04-08 patchlevel 160) [i686-darwin9]
[ruby-core:28252]

Description

=begin
When initializing a Hash with an enumerable as default value, Hash.new(obj) and Hash.new(&block) have different behaviours.

Example:
h = Hash.new([])
h[10] << 20
h #=> {}

h = Hash.new { |hash, key| hash[key] = [] }
hash[10] << 20
h #=> {10=>20}

The example similar when using a String instead of an Array as default value.
=end

Actions

Also available in: Atom PDF

Like0
Like0