Skip to content
This repository was archived by the owner on Feb 6, 2018. It is now read-only.

Commit 65b8ab0

Browse files
committed
trying to reduce "complexity" of #raise_inspect (rubychan#135)
1 parent 65a4b4d commit 65b8ab0

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

lib/coderay/scanner.rb

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,25 +307,27 @@ def reset_instance
307307
MESSAGE
308308

309309
# Scanner error with additional status information
310-
def raise_inspect msg, tokens, state = self.state, ambit = 30, backtrace = caller
311-
raise ScanError, SCAN_ERROR_MESSAGE % [
312-
File.basename(caller[0]),
313-
msg,
314-
tokens_size,
315-
tokens_last(10).map(&:inspect).join("\n"),
310+
def raise_inspect message, tokens, state = self.state, ambit = 30, backtrace = caller
311+
raise ScanError, SCAN_ERROR_MESSAGE % raise_inspect_arguments(message, tokens, state, ambit), backtrace
312+
end
313+
314+
def raise_inspect_arguments message, tokens, state, ambit
315+
return File.basename(caller[0]),
316+
message,
317+
tokens_size(tokens),
318+
tokens_last(tokens, 10).map(&:inspect).join("\n"),
316319
line, column, pos,
317320
matched, state || 'No state given!',
318321
bol?, eos?,
319322
binary_string[pos - ambit, ambit],
320-
binary_string[pos, ambit],
321-
], backtrace
323+
binary_string[pos, ambit]
322324
end
323325

324-
def tokens_size
326+
def tokens_size tokens
325327
tokens.size if tokens.respond_to?(:size)
326328
end
327329

328-
def tokens_last n
330+
def tokens_last tokens, n
329331
tokens.respond_to?(:last) ? tokens.last(n) : []
330332
end
331333

0 commit comments

Comments
 (0)