Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

He referenced not being alone in his assumptions, but this is basic ruby:

   >> a = b = [1,2]
   => [1, 2]
   >> c = a.dup
   => [1, 2]
   >> a==b
   => true
   >> a==c
   => true
   >> a.equal?(b)
   => true
   >> a.equal?(c)
   => false
Here's a better post on the topic: http://kentreis.wordpress.com/2007/02/08/identity-and-equali...


Well in fairness, I did mention that the realization made me feel stupid :-p

It's not necessarily obvious if you're coming from other languages that don't behave this way. That being said I'm surprised that I had never run into this problem before. I think that most of the time I had the right idea with not copying objects, but in this case I had memoized a method call and the Hash 'cache' was getting corrupted which was what brought it to my attention... A slightly more unusual situation.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: