Skip to content

Commit

Permalink
minor gensym cleanup; rename scope -> let
Browse files Browse the repository at this point in the history
  • Loading branch information
quix committed Sep 4, 2008
1 parent 9aba7b0 commit 32905e6
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions lib/quix/kernel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

module Quix
module Kernel
def scope
def let
yield self
end

Expand All @@ -13,31 +13,39 @@ class << self
end
end

def gensym(prefix = nil)
count = Quix::Kernel.instance_eval {
Thread.exclusive {
@private__gensym_count ||= 0
@private__gensym_count += 1
module Gensym
@mutex = Mutex.new
@count = 0

def gensym(prefix = nil)
count = Gensym.module_eval {
@mutex.synchronize {
@count += 1
}
}
}
:"#{prefix || :G}_#{count}_#{rand}"
"#{prefix || :G}_#{count}_#{rand}".to_sym
end
end
include Gensym

def call_private(method, *args, &block)
instance_eval { send(method, *args, &block) }
end

# execute a block with warnings turned off
def no_warnings
def with_warnings(value = true)
previous = $VERBOSE
$VERBOSE = value
begin
$VERBOSE = nil
yield
ensure
$VERBOSE = previous
end
end

def no_warnings(&block)
with_warnings(false, &block)
end

def abort_on_exception(value = true)
previous = Thread.abort_on_exception
Thread.abort_on_exception = value
Expand Down

0 comments on commit 32905e6

Please sign in to comment.