1
我想知道如何以编程方式提前查看Digest
模块上可用的每个常量。下面看到的行为是由于const_missing
使用here:显示“摘要”中的所有常量
require 'digest'
Digest.constants
#=> [:Class, :REQUIRE_MUTEX, :Instance, :Base]
Digest::MD5
Digest.constants
#=> [:Class, :REQUIRE_MUTEX, :Instance, :Base, :MD5]
Digest::SHA1
Digest.constants
#=> [:Class, :REQUIRE_MUTEX, :Instance, :Base, :MD5, :SHA1]
考虑到他们在可能的消化元编程,我怎么能知道所有可能的可用摘要?
知识,出现在红宝石2.4.1可用的那些应该是[:SHA256, :SHA384, :SHA512, :SHA1, :SHA2, :MD5, :RMD160]
一种方法是查看源代码:https://github.com/ruby/ruby/tree/trunk/ext/digest –
除了此评论似乎另有说明: https://github.com/ ruby/ruby/blob/trunk/ext/digest/lib/digest.rb#L103 您可以加载不在源代码中的SHA512。 – BookOfGreg
好点。那么,因为常量是懒惰加载的,我不知道如何在不知道它们的情况下列出它们。 ¡\\ _(ツ)_ /¯ –