lib/rouge/lexer.rb in rouge-0.2.6 vs lib/rouge/lexer.rb in rouge-0.2.7

- old
+ new

@@ -257,12 +257,25 @@ # information that is unnecessary for lexing in the real world. # # @example # debug { "hello, world!" } def debug(&b) - @debug = option(:debug) unless instance_variable_defined?(:@debug) + # This method is a hotspot, unfortunately. + # + # For performance reasons, the "debug" option of a lexer cannot + # be changed once it has begun lexing. This method will redefine + # itself on the first call to a noop if "debug" is not set. + if option(:debug) + class << self + def debug; puts yield; end + end + else + class << self + def debug; end + end + end - puts(b.call) if @debug + debug(&b) end # @abstract # # Called after each lex is finished. The default implementation