Regex#hash 
Author Message
 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.



Mon, 30 May 2005 05:00:45 GMT  
 Regex#hash
Hi,

In message "Regex#hash"

|Why doesn't Regex#hash behave like String#hash?

Sounds good.  I will add this to 1.7.

                                                        matz.



Mon, 30 May 2005 16:30:23 GMT  
 Regex#hash

Quote:

> Hi,

> In message "Regex#hash"

> |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! :)



Wed, 01 Jun 2005 06:11:38 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Hash.new(Hash.new) doesn't use Hash.new as default value

2. grep regex to ruby regex...

3. Regex++ or other Regex lib for Fortran?

4. Python regex / libc regex interactions

5. obj.hash now == obj.hash after?

6. Hash compression (Hash 'consing') circa 1957

7. hash as key in hash

8. Sorting a Hash by value of integer stored in the Hash

9. Hash#index !==> Hash#indexes

10. Hash#index !==> Hash#indexes

11. Hash.new {block} / Hash#default_proc{,_set}

12. Moron hashing (rehashing hashing again)

 

 
Powered by phpBB® Forum Software