Project

General

Profile

Bug #11035

Calling #hash method: inconsistency between dynamic and static symbols

Added by ko1 (Koichi Sasada) over 5 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:<unknown>]

Description

There is an inconsistency between static symbols and dynamic symbols.

class Symbol
  def hash
    raise
  end
end

h = {}
h[:foo] = 1          #=> no problem
h['bar'.to_sym] = 2  #=> unhandled exception

I think it should be same behavior.
My favorite is skip calling #hash for all Symbol objects.

#1

Updated by nobu (Nobuyoshi Nakada) over 5 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

Applied in changeset r50182.


hash.c: compare symbols by identities

  • hash.c (rb_any_hash): Symbols are compared by the identities always. [ruby-core:68767] [Bug #11035]
#2

Updated by usa (Usaku NAKAMURA) over 5 years ago

  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.0.0: DONTNEED, 2.1: DONTNEED, 2.2: REQUIRED

Updated by nagachika (Tomoyuki Chikanaga) over 5 years ago

  • Backport changed from 2.0.0: DONTNEED, 2.1: DONTNEED, 2.2: REQUIRED to 2.0.0: DONTNEED, 2.1: DONTNEED, 2.2: DONE

Backported into ruby_2_2 branch at rr50620.

Also available in: Atom PDF