From aa93af4cbc465d90db8f1f27477214ec119223a3 Mon Sep 17 00:00:00 2001 From: Kornelius Kalnbach Date: Sat, 13 Feb 2016 00:32:56 +0100 Subject: quick increment/decrement, yay! --- lib/coderay/rule_based_scanner.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lib/coderay/rule_based_scanner.rb') diff --git a/lib/coderay/rule_based_scanner.rb b/lib/coderay/rule_based_scanner.rb index 2154fb7..ba49ccf 100644 --- a/lib/coderay/rule_based_scanner.rb +++ b/lib/coderay/rule_based_scanner.rb @@ -13,6 +13,7 @@ module CodeRay CheckIf = Class.new Check CheckUnless = Class.new Check ValueSetter = Struct.new :targets, :value + Increment = Struct.new :targets, :operation, :value Continue = Class.new class << self @@ -172,6 +173,16 @@ module CodeRay @code << " #{action.targets.join(' = ')} = #{action.value.inspect}\n" end + when Increment + case action.value + when Proc + @code << " #{action.targets.join(' = ')} #{action.operation}= #{make_callback(action.value)}\n" + when Symbol + @code << " #{action.targets.join(' = ')} #{action.operation}= #{action.value}\n" + else + @code << " #{action.targets.join(' = ')} #{action.operation}= #{action.value.inspect}\n" + end + when Proc @code << " #{make_callback(action)}\n" @@ -240,6 +251,14 @@ module CodeRay ValueSetter.new Array(flags), nil end + def increment *counters + Increment.new Array(counters), :+, 1 + end + + def decrement *counters + Increment.new Array(counters), :-, 1 + end + def continue Continue.new end -- cgit v1.2.1