Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

use Proc#call instead of Object#instance_exec

  • Loading branch information...
commit a3ca1308d8536cd846e422ea311c4ca4959620a6 1 parent 76dbfbf
Dominik Sander dsander authored
25 lib/em-proxy.rb
... ... @@ -1,30 +1,5 @@
1 1 $:.unshift(File.dirname(__FILE__) + '/../lib')
2 2
3   -unless respond_to?(:instance_exec)
4   - # based on Bounded Spec InstanceExec (Mauricio Fernandez)
5   - # http://eigenclass.org/hiki/bounded+space+instance_exec
6   - # - uses singleton_class of matcher instead of global
7   - # InstanceExecHelper module
8   - # - this keeps it scoped to this class only, which is the
9   - # only place we need it
10   - # - only necessary for ruby 1.8.6
11   - def instance_exec(*args, &block)
12   - singleton_class = (class << self; self; end)
13   - begin
14   - orig_critical, Thread.critical = Thread.critical, true
15   - n = 0
16   - n += 1 while respond_to?(method_name="__instance_exec#{n}")
17   - singleton_class.module_eval{ define_method(:__instance_exec, &block) }
18   - ensure
19   - Thread.critical = orig_critical
20   - end
21   - begin
22   - return send(:__instance_exec, *args)
23   - ensure
24   - singleton_class.module_eval{ remove_method(:__instance_exec) } rescue nil
25   - end
26   - end
27   -end
28 3
29 4 require "rubygems"
30 5 require "eventmachine"
9 lib/em-proxy/connection.rb
@@ -84,10 +84,11 @@ def unbind_backend(name)
84 84 private
85 85
86 86 def debug(*data)
87   - return unless @debug
88   - require 'pp'
89   - pp data
90   - puts
  87 + if @debug
  88 + require 'pp'
  89 + pp data
  90 + puts
  91 + end
91 92 end
92 93 end
93 94 end
2  lib/em-proxy/proxy.rb
@@ -9,7 +9,7 @@ def self.start(options, &blk)
9 9
10 10 EventMachine::start_server(options[:host], options[:port],
11 11 EventMachine::ProxyServer::Connection, options) do |c|
12   - instance_exec(c, &blk)
  12 + blk.call(c)
13 13 end
14 14 end
15 15 end

0 comments on commit a3ca130

Please sign in to comment.
Something went wrong with that request. Please try again.