类 Object

公共实例方法

Digest(name) → digest_subclass 点击切换源代码

以线程安全的方式返回由 name 指定的 Digest 子类,即使涉及按需加载。

require 'digest'

Digest("MD5")
# => Digest::MD5

Digest(:SHA256)
# => Digest::SHA256

Digest(:Foo)
# => LoadError: library not found for class Digest::Foo -- digest/foo
# File digest/lib/digest.rb, line 110
def Digest(name)
  const = name.to_sym
  Digest::REQUIRE_MUTEX.synchronize {
    # Ignore autoload's because it is void when we have #const_missing
    Digest.const_missing(const)
  }
rescue LoadError
  # Constants do not necessarily rely on digest/*.
  if Digest.const_defined?(const)
    Digest.const_get(const)
  else
    raise
  end
end
digest_conf(name) 点击切换源代码
# File digest/digest_conf.rb, line 3
def digest_conf(name)
  unless with_config("bundled-#{name}")
    cc = with_config("common-digest")
    if cc != false or /\b#{name}\b/ =~ cc
      if File.exist?("#$srcdir/#{name}cc.h") and
        have_header("CommonCrypto/CommonDigest.h")
        $defs << "-D#{name.upcase}_USE_COMMONDIGEST"
        $headers << "#{name}cc.h"
        return :commondigest
      end
    end
  end
  $objs << "#{name}.#{$OBJEXT}"
  return
end