Heads up: This description was created by AI and might not be 100% accurate.

md5sum.rb

This Ruby code snippet demonstrates the usage of the Digest module in Ruby to calculate MD5 hashes. The first line requires the digest/md5 library, which is part of the standard library in Ruby.

The second line uses the hexdigest method provided by the Digest::MD5 class to calculate the MD5 hash of a string. In this case, the string 'ruby' is passed as an argument to the method. The resulting MD5 hash is returned as a hexadecimal string.

The third line uses the file method provided by the Digest::MD5 class to calculate the MD5 hash of a file. In this case, the file 'input/digest/md5sum.rb' is passed as an argument to the method. The resulting MD5 hash is returned as a hexadecimal string.

Note that in order to use these methods, you need to have the digest library installed on your system. You can install it using the Ruby package manager, such as gem install digest.

Ruby code snippet

require 'digest/md5'
#=> true

Digest::MD5.hexdigest('ruby')
#=> "58e53d1324eef6265fdb97b08ed9aadf"

Digest::MD5.file('input/digest/md5sum.rb').to_s
#=> "73de438f54f53157053373a820c72ff1"

Executed with Ruby 3.4.4.