Question

I want to see the hash created by the function Digest::SHA2.hexdigest. I do not have Ruby installed, so I went for the online irb. Typing

Digest::SH­A2.hexdige­st("hello"­)

gives

=> #<NameError: uninitialized constant Digest>

Is it possible to add the needed library in any online irb?

Was it helpful?

Solution

You need to do as below :

2.0.0-p0 :003 > require 'digest'
 => true 
2.0.0-p0 :004 > Digest::SHA2.hexdigest("hello")
 => "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824" 
2.0.0-p0 :005 > 

So do first require 'digest'.

Try in tutorialspoint

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top