deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1207915 - in /deltacloud/trunk/server/lib/deltacloud: core_ext.rb core_ext/proc.rb
Date Tue, 29 Nov 2011 15:31:53 GMT
Author: mfojtik
Date: Tue Nov 29 15:31:52 2011
New Revision: 1207915

URL: http://svn.apache.org/viewvc?rev=1207915&view=rev
Log:
Core: Added callback extension for Proc

Added:
    deltacloud/trunk/server/lib/deltacloud/core_ext/proc.rb
      - copied, changed from r1207914, deltacloud/trunk/server/lib/deltacloud/core_ext.rb
Modified:
    deltacloud/trunk/server/lib/deltacloud/core_ext.rb

Modified: deltacloud/trunk/server/lib/deltacloud/core_ext.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/deltacloud/core_ext.rb?rev=1207915&r1=1207914&r2=1207915&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/deltacloud/core_ext.rb (original)
+++ deltacloud/trunk/server/lib/deltacloud/core_ext.rb Tue Nov 29 15:31:52 2011
@@ -18,3 +18,4 @@ require 'deltacloud/core_ext/string'
 require 'deltacloud/core_ext/integer'
 require 'deltacloud/core_ext/hash'
 require 'deltacloud/core_ext/array'
+require 'deltacloud/core_ext/proc'

Copied: deltacloud/trunk/server/lib/deltacloud/core_ext/proc.rb (from r1207914, deltacloud/trunk/server/lib/deltacloud/core_ext.rb)
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/deltacloud/core_ext/proc.rb?p2=deltacloud/trunk/server/lib/deltacloud/core_ext/proc.rb&p1=deltacloud/trunk/server/lib/deltacloud/core_ext.rb&r1=1207914&r2=1207915&rev=1207915&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/deltacloud/core_ext.rb (original)
+++ deltacloud/trunk/server/lib/deltacloud/core_ext/proc.rb Tue Nov 29 15:31:52 2011
@@ -1,4 +1,3 @@
-#
 # Licensed to the Apache Software Foundation (ASF) under one or more
 # contributor license agreements.  See the NOTICE file distributed with
 # this work for additional information regarding copyright ownership.  The
@@ -14,7 +13,15 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
-require 'deltacloud/core_ext/string'
-require 'deltacloud/core_ext/integer'
-require 'deltacloud/core_ext/hash'
-require 'deltacloud/core_ext/array'
+# Original code copied from: http://www.mattsears.com/articles/2011/11/27/ruby-blocks-as-dynamic-callbacks
+# Copyright 2011 Matt Sears.
+class Proc
+  def callback(callable, *args)
+    self === Class.new do
+      method_name = callable.to_sym
+      define_method(method_name) { |&block| block.nil? ? true : block.call(*args) }
+      define_method("#{method_name}?") { true }
+      def method_missing(method_name, *args, &block) false; end
+    end.new
+  end
+end



Mime
View raw message