On Thursday, 14 February 2013 at 11:30 AM, Aaron Patterson wrote:
> Yes, this is probably not thread safe, but if people *know* it's not
> thread safe, then they can lock:
> 
> begin
> Symbol.lock
> Symbol.freeze_symbols
> YAML.load(...)
> ensure
> Symbol.thaw_symbols
> Symbol.unlock
> end

I think this is a perfect contender for a block. There can be a global 'symbol_freeze_count' that is incremented when the block enters, and decremented on the way out. 

For example:

  Symbol.frozen do
    :foo # ok because this is symbol-ified by the parser beforehand
    eval ":foo" # exception
    "foo".to_sym # exception
  end

This is better because it is re-entrant, unlike a pair of 'freeze' and 'thaw' methods.