ruby - Strings that compare equal don't find same objects in Hash -


i have 2 strings appear equal:

context = "marriott international world’s admired lodging company fortune 14th yr. via @fortunemagazine http://cnnmon.ie/1kcfzsq" slice_str = context.slice(105,24) # => "http://cnnmon.ie/1kcfzsq" str = "http://cnnmon.ie/1kcfzsq"  slice_str == str                  # => true slice_str.eql? str                # => true 

but when values in hash keys strings, not return same thing in ruby 2.1.0 , ruby 2.1.1:

redirects = {"http://cnnmon.ie/1kcfzsq"=>""} redirects.key?(slice_str)         # => false redirects.key?(str)               # => true 

what explanation there behaviour? ruby 1.9.3 works expected.

this bug in ruby < 2.1.3

$ rvm use 2.1.2 using /users/richniles/.rvm/gems/ruby-2.1.2 $ irb 2.1.2 :001 > context = "marriott international world’s admired lodging company fortune 14th yr. via @fortunemagazine http://cnnmon.ie/1kcfzsq"  => "marriott international world’s admired lodging company fortune 14th yr. via @fortunemagazine http://cnnmon.ie/1kcfzsq"  2.1.2 :002 > slice_str = context.slice(105,24) # => "http://cnnmon.ie/1kcfzsq"  => "http://cnnmon.ie/1kcfzsq"  2.1.2 :003 > str = "http://cnnmon.ie/1kcfzsq"  => "http://cnnmon.ie/1kcfzsq"  2.1.2 :004 > redirects = {"http://cnnmon.ie/1kcfzsq"=>""}  => {"http://cnnmon.ie/1kcfzsq"=>""}  2.1.2 :005 > redirects.key?(slice_str)   => false  2.1.2 :006 > redirects.key?(str)    => true  

but same in ruby 2.1.3:

 $ rvm use 2.1.3  using /users/richniles/.rvm/gems/ruby-2.1.3  $ irb  2.1.3 :001 > context = "marriott international world’s admired lodging company fortune 14th yr. via @fortunemagazine http://cnnmon.ie/1kcfzsq"   => "marriott international world’s admired lodging company fortune 14th yr. via @fortunemagazine http://cnnmon.ie/1kcfzsq"   2.1.3 :002 > slice_str = context.slice(105,24) # => "http://cnnmon.ie/1kcfzsq"   => "http://cnnmon.ie/1kcfzsq"   2.1.3 :003 > str = "http://cnnmon.ie/1kcfzsq"   => "http://cnnmon.ie/1kcfzsq"   2.1.3 :004 > redirects = {"http://cnnmon.ie/1kcfzsq"=>""}   => {"http://cnnmon.ie/1kcfzsq"=>""}   2.1.3 :005 > redirects.key?(slice_str)    => true   2.1.3 :006 > redirects.key?(str)     => true  

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -