[macruby-changes] [3428] MacRuby/trunk/ext/openssl/lib/openssl/digest.rb

source_changes at macosforge.org source_changes at macosforge.org
Wed Feb 3 18:09:55 PST 2010


Revision: 3428
          http://trac.macosforge.org/projects/ruby/changeset/3428
Author:   lsansonetti at apple.com
Date:     2010-02-03 18:09:52 -0800 (Wed, 03 Feb 2010)
Log Message:
-----------
clean bad code (thanks Eloy)

Modified Paths:
--------------
    MacRuby/trunk/ext/openssl/lib/openssl/digest.rb

Modified: MacRuby/trunk/ext/openssl/lib/openssl/digest.rb
===================================================================
--- MacRuby/trunk/ext/openssl/lib/openssl/digest.rb	2010-02-04 01:43:46 UTC (rev 3427)
+++ MacRuby/trunk/ext/openssl/lib/openssl/digest.rb	2010-02-04 02:09:52 UTC (rev 3428)
@@ -30,23 +30,31 @@
         super(data, name)
     end
 
-    alg.each{|name|
-      klass = Class.new(Digest){
-        define_method(:initialize){|*data|
-          if data.length > 1
-            raise ArgumentError,
-              "wrong number of arguments (#{data.length} for 1)"
-          end
-          super(name, data.first)
-        }
-      }
-      singleton = (class << klass; self; end)
-      singleton.class_eval{
-        define_method(:digest){|data| Digest.digest(name, data) }
-        define_method(:hexdigest){|data| Digest.hexdigest(name, data) }
-      }
+    class Stub < Digest
+      class << self
+        def digest(data)
+          Digest.digest(name, data)
+        end
+
+        def hexdigest(data)
+          Digest.hexdigest(name, data)
+        end
+      end
+
+      def initialize(*data)
+        if data.length > 1
+          raise ArgumentError,
+            "wrong number of arguments (#{data.length} for 1)"
+        end
+        super(self.class.instance_variable_get(:@name), data[0])
+      end
+    end
+
+    alg.each do |name|
+      klass = Class.new(Stub)
+      klass.instance_variable_set(:@name, name)
       const_set(name, klass)
-    }
+    end
 
     # This class is only provided for backwards compatibility.  Use OpenSSL::Digest in the future.
     class Digest < Digest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100203/0f349c88/attachment.html>


More information about the macruby-changes mailing list