From 65a4b4dfe93e9be0d9f753f063b8f77f8be5af77 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Mon, 10 Jun 2013 18:23:17 +0200 Subject: trying to reduce "complexity" of #raise_inspect (#135) --- lib/coderay/scanner.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'lib/coderay') diff --git a/lib/coderay/scanner.rb b/lib/coderay/scanner.rb index 9a5be58..68451ae 100644 --- a/lib/coderay/scanner.rb +++ b/lib/coderay/scanner.rb @@ -289,7 +289,7 @@ module CodeRay SCAN_ERROR_MESSAGE = <<-MESSAGE -***ERROR in %s: %s (after %d tokens) +***ERROR in %s: %s (after %s tokens) tokens: %s @@ -311,8 +311,8 @@ surrounding code: raise ScanError, SCAN_ERROR_MESSAGE % [ File.basename(caller[0]), msg, - tokens.respond_to?(:size) ? tokens.size : '[tokens.size undefined]', - tokens.respond_to?(:last) ? tokens.last(10).map(&:inspect).join("\n") : '[tokens.last undefined]', + tokens_size, + tokens_last(10).map(&:inspect).join("\n"), line, column, pos, matched, state || 'No state given!', bol?, eos?, @@ -321,6 +321,14 @@ surrounding code: ], backtrace end + def tokens_size + tokens.size if tokens.respond_to?(:size) + end + + def tokens_last n + tokens.respond_to?(:last) ? tokens.last(n) : [] + end + # Shorthand for scan_until(/\z/). # This method also avoids a JRuby 1.9 mode bug. def scan_rest -- cgit v1.2.1