Regex#hash

Why doesn’t Regex#hash behave like String#hash?

irb(main):009:0> “a”.hash
100
irb(main):010:0> “a”.hash
100
irb(main):011:0> /a/.hash
537976558
irb(main):012:0> /a/.hash
537970778

And yet…

irb(main):013:0> /a/ == /a/
true

Regexes seem pretty immutable to me, or more so than strings anyway, so
it seems resonable to hash based on whatever Regex#== looks at, rather
than use #id as the hash val.

Hi,

···

In message “Regex#hash” on 02/12/12, Joel VanderWerf vjoel@PATH.Berkeley.EDU writes:

Why doesn’t Regex#hash behave like String#hash?

Sounds good. I will add this to 1.7.

						matz.

Yukihiro Matsumoto wrote:

Hi,

Why doesn’t Regex#hash behave like String#hash?

Sounds good. I will add this to 1.7.

  					matz.

Amazing…

irb(main):001:0> RUBY_VERSION
=> “1.7.3”
irb(main):002:0> RUBY_RELEASE_DATE
=> “2002-12-12”
irb(main):003:0> /a/.hash
=> 4456
irb(main):004:0> /a/.hash
=> 4456

Thanks, matz! :slight_smile:

···

In message “Regex#hash” > on 02/12/12, Joel VanderWerf vjoel@PATH.Berkeley.EDU writes: