deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core] CIMI: Fixed incompatibility between 1.9 and 1.8 in Proc callback
Date Tue, 17 Jan 2012 16:15:05 GMT
From: Michal Fojtik <mfojtik@redhat.com>


Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 server/lib/deltacloud/core_ext/proc.rb |   20 ++++++++++++--------
 1 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/server/lib/deltacloud/core_ext/proc.rb b/server/lib/deltacloud/core_ext/proc.rb
index 3c443ff..1917123 100644
--- a/server/lib/deltacloud/core_ext/proc.rb
+++ b/server/lib/deltacloud/core_ext/proc.rb
@@ -13,15 +13,19 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
-# Original code copied from: http://www.mattsears.com/articles/2011/11/27/ruby-blocks-as-dynamic-callbacks
-# Copyright 2011 Matt Sears.
+# Original code copied from https://gist.github.com/1417762
+# Copyright 2011 Emmanuel Oga.
+
 class Proc
+
+  Callback = Struct.new(:called, :args) do
+    def method_missing(name, *)
+      name == :"#{called}?" || (name == called && block_given? && yield(*args))
+    end
+  end
+
   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
+    call Callback.new(callable, *args)
   end
+
 end
-- 
1.7.4.4


Mime
View raw message