Skip to content

Instantly share code, notes, and snippets.

@ilake
Created December 10, 2012 14:42
Show Gist options
  • Select an option

  • Save ilake/4250924 to your computer and use it in GitHub Desktop.

Select an option

Save ilake/4250924 to your computer and use it in GitHub Desktop.
Digest::MD5
[1] pry(main)> Digest::MD5.new.update('version-1')
=> #<Digest::MD5: e8444fc50e000a592c6f49872490349e>
[2] pry(main)> Digest::MD5.new.update('version-1').update('mini-2')
=> #<Digest::MD5: 9f328f25432758cd63ba0ddd38024364>
[3] pry(main)> Digest::MD5.new.update('version-1').update('mini-2').hexdigest
=> "9f328f25432758cd63ba0ddd38024364"
[4] pry(main)> Digest::MD5.hexdigest('version-1')
=> "e8444fc50e000a592c6f49872490349e"
[59] pry(main)> d = Digest::MD5.new.update('version-1')
=> #<Digest::MD5: e8444fc50e000a592c6f49872490349e>
[60] pry(main)> d << 'mini-2'
=> #<Digest::MD5: 9f328f25432758cd63ba0ddd38024364>
[62] pry(main)> Digest::MD5.new.update('version-1').update('mini-2').reset.update('version-1')
=> #<Digest::MD5: e8444fc50e000a592c6f49872490349e>
# object 才可以這樣chain 下去
# http://rubydoc.info/stdlib/digest/1.9.3/Digest/MD5
# http://www.ruby-doc.org/stdlib-1.9.3/libdoc/digest/rdoc/Digest/Instance.html#method-i-update
# Updates the digest using a given string and returns self.
# The update() method and the left-shift operator are overridden by each
# implementation subclass. (One should be an alias for the other)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment