To create an MD5 hash from a string in Ruby, you can use the Digest
library that comes with Ruby's standard library:
main.rb141 chars7 lines
In the above code block, we require the digest
library, which gives us access to a set of hash functions, including MD5.
We create a string variable with the value "hello world"
, and then call Digest::MD5.hexdigest
on the string to generate an MD5 hash. The hexdigest
method returns the hash as a string of hexadecimal digits.
We then print the resulting MD5 hash to the console.
gistlibby LogSnag