diff options
author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-10-13 12:02:32 +0000 |
---|---|---|
committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2006-10-13 12:02:32 +0000 |
commit | 3a4ce48c7502afbfd9303b31ada124e892a249fb (patch) | |
tree | 606795abab1fb20a372e43aa6b48e3d09815d743 /ext | |
parent | f678390e1f7e2e8556b160202a482baa64d67f9d (diff) | |
download | ruby-3a4ce48c7502afbfd9303b31ada124e892a249fb.tar.gz |
* ext/digest/lib/digest.rb (Digest): Try to auto-load non-standard
digest modules when a specified digest class is missing.
* ext/digest/lib/digest.rb: Define Digest(name) for ease of
dynamically selecting a hashing algorithm.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r-- | ext/digest/lib/digest.rb | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/ext/digest/lib/digest.rb b/ext/digest/lib/digest.rb index c277a0eea5..dc91e9444e 100644 --- a/ext/digest/lib/digest.rb +++ b/ext/digest/lib/digest.rb @@ -1,13 +1,21 @@ require 'digest.so' module Digest - autoload "MD5", "digest/md5" - autoload "RMD160", "digest/rmd160" - autoload "SHA1", "digest/sha1" autoload "SHA256", "digest/sha2" autoload "SHA384", "digest/sha2" autoload "SHA512", "digest/sha2" + def self.const_missing(name) + begin + require File.join('digest', name.downcase) + + return Digest.const_get(name) if Digest.const_defined?(name) + rescue LoadError => e + end + + raise NameError, "Digest class not found: Digest::#{name}" + end + class Base # creates a digest object and read given file, _name_. # @@ -25,3 +33,7 @@ module Digest end end end + +def Digest(name) + Digest.const_get(name) +end |