Ruby 1.9.3中的摘要:: MD5

cod*_*nny 8 ruby md5 rubygems irb ruby-1.9.3

我在这里碰到了一些奇怪的东西.我有一个"身份验证器"依赖ND5来哈希我们匹配的某个字符串作为密码.我运行测试时的问题是:

NoMethodError: undefined method `md5' for #<CASServer::Authenticators::Billing:0x007fd8e6c906a0>
./models/authenticators/billing.rb:63:in `validate'
./routes/login.rb:166:in `block (2 levels) in <class:Server>'
./routes/login.rb:158:in `each'
./routes/login.rb:158:in `block in <class:Server>'
(eval):2:in `click_button'
./features/step_definitions/when_steps.rb:32:in `/^I enter "(.*)" as username and the generated username password and log in$/'
./features/rubycas.login.feature:14:in `When I enter "username" as username and the generated username password and log in'
Run Code Online (Sandbox Code Playgroud)

所以基本上他不承认MD5是Digest库的一部分.在IDE中以及在IRB控制台中运行测试时会发生此问题:

1.9.3-p125 :001 > require "digest/md5" and Digest::MD5("test")
NoMethodError: undefined method `MD5' for Digest:Module
Run Code Online (Sandbox Code Playgroud)

但是,当我运行以下内容时:

[root@DCUDEV01 /home/morn/rubycas/current]# ruby
require "digest/md5" and Digest::MD5("test")
Run Code Online (Sandbox Code Playgroud)

我没有收到任何错误,转储或异常.Ruby只接受它.为了让这个MD5工作起作用,我缺少什么?

use*_*207 33

摘要:: MD5不是方法,而是模块.尝试

Digest::MD5.digest("test")
Run Code Online (Sandbox Code Playgroud)

  • 摘要:: MD5.hexdigest也很不错 (18认同)