Permalink
Browse files

use Proc#call instead of Object#instance_exec

  • Loading branch information...
dsander committed Dec 21, 2009
1 parent 76dbfbf commit a3ca1308d8536cd846e422ea311c4ca4959620a6
Showing with 6 additions and 30 deletions.
  1. +0 −25 lib/em-proxy.rb
  2. +5 −4 lib/em-proxy/connection.rb
  3. +1 −1 lib/em-proxy/proxy.rb
View
@@ -1,30 +1,5 @@
$:.unshift(File.dirname(__FILE__) + '/../lib')
-unless respond_to?(:instance_exec)
- # based on Bounded Spec InstanceExec (Mauricio Fernandez)
- # http://eigenclass.org/hiki/bounded+space+instance_exec
- # - uses singleton_class of matcher instead of global
- # InstanceExecHelper module
- # - this keeps it scoped to this class only, which is the
- # only place we need it
- # - only necessary for ruby 1.8.6
- def instance_exec(*args, &block)
- singleton_class = (class << self; self; end)
- begin
- orig_critical, Thread.critical = Thread.critical, true
- n = 0
- n += 1 while respond_to?(method_name="__instance_exec#{n}")
- singleton_class.module_eval{ define_method(:__instance_exec, &block) }
- ensure
- Thread.critical = orig_critical
- end
- begin
- return send(:__instance_exec, *args)
- ensure
- singleton_class.module_eval{ remove_method(:__instance_exec) } rescue nil
- end
- end
-end
require "rubygems"
require "eventmachine"
@@ -84,10 +84,11 @@ def unbind_backend(name)
private
def debug(*data)
- return unless @debug
- require 'pp'
- pp data
- puts
+ if @debug
+ require 'pp'
+ pp data
+ puts
+ end
end
end
end
View
@@ -9,7 +9,7 @@ def self.start(options, &blk)
EventMachine::start_server(options[:host], options[:port],
EventMachine::ProxyServer::Connection, options) do |c|
- instance_exec(c, &blk)
+ blk.call(c)
end
end
end

0 comments on commit a3ca130

Please sign in to comment.