• Login
sketchucation logo sketchucation
  • Login
⚠️ Libfredo 15.4b | Minor release with bugfixes and improvements Update

Mad behaviour of String#hash

Scheduled Pinned Locked Moved Developers' Forum
6 Posts 4 Posters 484 Views 4 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    AdamB
    last edited by 23 Aug 2014, 16:47

    I recently fixed a bug in LightUp that was the result of a subtle change in the method #hash between Ruby 1.8 and 2.0 that I thought I'd share.

    Previously, "adam".hash would always give the same result - because its a hash of the string "adam" - which is what you'd expect.

    Ruby 2.0, chooses to give you a different result every time you launch Ruby. Which is quite idiotic.

    The upshot is you cannot rely on creating digests that persist across sessions. 😠

    Sadly, there is no doubt a thread somewhere in Rubyland explaining why its a stroke of brilliance.. sigh

    Developer of LightUp Click for website

    1 Reply Last reply Reply Quote 0
    • D Offline
      Dan Rathbun
      last edited by 23 Aug 2014, 23:20

      @adamb said:

      Sadly, there is no doubt a thread somewhere in Rubyland explaining why its a stroke of brilliance.. sigh

      Try:
      https://bugs.ruby-lang.org/search?utf8=%E2%9C%93%26amp;q=String%23hash

      I'm not here much anymore.

      1 Reply Last reply Reply Quote 0
      • T Offline
        TIG Moderator
        last edited by 24 Aug 2014, 11:14

        Or for an explanation see this http://stackoverflow.com/questions/6783811/why-is-ruby-string-hash-inconsistent-across-machines

        TIG

        1 Reply Last reply Reply Quote 0
        • T Offline
          tt_su
          last edited by 24 Aug 2014, 13:32

          Oh... I might have to have a scan of my extensions. I'm not sure if I store string hashes, but I wouldn't be surprised.
          This .hash change affects only String, yes?

          Thanks for the heads up.

          1 Reply Last reply Reply Quote 0
          • D Offline
            Dan Rathbun
            last edited by 24 Aug 2014, 22:14

            @tig said:

            Or for an explanation see this http://stackoverflow.com/questions/6783811/why-is-ruby-string-hash-inconsistent-across-machines

            Which actually quotes from the Ruby bugs dB at:
            Bug #4103 (Closed): String#hash not returning consistent values in different sessions

            I'm not here much anymore.

            1 Reply Last reply Reply Quote 0
            • D Offline
              Dan Rathbun
              last edited by 24 Aug 2014, 22:23

              @tt_su said:

              This .hash change affects only String, yes?

              The above Ruby bugs thread mentions Object#hash being overhauled (which is inherited by every object, unless overriden.)

              So a test under SketchUp 2014 & Ruby 2.0:

              (1) Open a SketchUp session, and in the console:
              Sketchup.hash %(#004000)[>> -112701995]

              This is the method that the Module class inherits from Object.

              (2) Close this SketchUp session, reopen SketchUp, and in the console:
              Sketchup.hash %(#004000)[>> -226388390]

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              1 / 1
              • First post
                1/6
                Last post
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement