You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2012/01/18 10:09:28 UTC
svn commit: r1232794 -
/deltacloud/trunk/server/lib/deltacloud/core_ext/proc.rb
Author: mfojtik
Date: Wed Jan 18 09:09:27 2012
New Revision: 1232794
URL: http://svn.apache.org/viewvc?rev=1232794&view=rev
Log:
CIMI: Fixed incompatibility between 1.9 and 1.8 in Proc callback
Modified:
deltacloud/trunk/server/lib/deltacloud/core_ext/proc.rb
Modified: deltacloud/trunk/server/lib/deltacloud/core_ext/proc.rb
URL: http://svn.apache.org/viewvc/deltacloud/trunk/server/lib/deltacloud/core_ext/proc.rb?rev=1232794&r1=1232793&r2=1232794&view=diff
==============================================================================
--- deltacloud/trunk/server/lib/deltacloud/core_ext/proc.rb (original)
+++ deltacloud/trunk/server/lib/deltacloud/core_ext/proc.rb Wed Jan 18 09:09:27 2012
@@ -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