Class: Nitpick::LocalVariableCounter

Class | Nitpick::LocalVariableCounter
In: | lib/nitpick/local_variable_counter.rb
Parent: | Nitpicker

### Methods

call new process_args process_block_arg process_call process_iasgn process_lasgn process_lvar use uses

### Public Class methods

new(klass, meth)

[Source]

    # File lib/nitpick/local_variable_counter.rb, line 3
        def initialize(klass, meth)
          super
          # uses.succ each time a local variable is referenced or assigned to
          # calls.succ each time a message is sent to a lvar (foo.bar)
          @lvars = Hash.new {|h,k| h[k] = {:uses => 0, :calls => 0}}
          @args = []
        end

### Public Instance methods

call(name)

[Source]

    # File lib/nitpick/local_variable_counter.rb, line 19
        def call(name)
          @lvars[name][:calls] += 1
        end

process_args(exp)

[Source]

    # File lib/nitpick/local_variable_counter.rb, line 58
        def process_args(exp)
          exp.each do |arg|
            next unless arg.is_a? Symbol

            name = arg.to_s.gsub(/^\*/, '')
            next if name == ""

            @args << name.to_sym
            use name.to_sym
          end

          exp.clear

          s(:args, *@args)
        end

process_block_arg(exp)

[Source]

    # File lib/nitpick/local_variable_counter.rb, line 74
        def process_block_arg(exp)
          name = exp.shift
          @args << name
          use name
          s(:block_arg, name)
        end

process_call(exp)

[Source]

    # File lib/nitpick/local_variable_counter.rb, line 42
        def process_call(exp)
          recv = process(exp.shift)
          meth = exp.shift
          args = process(exp.shift)

          call recv.last if recv.first == :lvar

          s(:call, recv, meth, args)
        end

process_iasgn(exp)

[Source]

    # File lib/nitpick/local_variable_counter.rb, line 33
        def process_iasgn(exp)
          name = exp.shift
          value = exp.shift

          process(value)

          s(:iasgn, name, value)
        end

process_lasgn(exp)

[Source]

    # File lib/nitpick/local_variable_counter.rb, line 23
        def process_lasgn(exp)
          name = exp.shift
          value = exp.shift

          use name
          process(value)

          s(:lasgn, name, value)
        end

process_lvar(exp)

[Source]

    # File lib/nitpick/local_variable_counter.rb, line 52
        def process_lvar(exp)
          name = exp.shift
          use name
          s(:lvar, name)
        end

use(name)

[Source]

    # File lib/nitpick/local_variable_counter.rb, line 15
        def use(name)
          @lvars[name][:uses] += 1
        end

uses(name)

[Source]

    # File lib/nitpick/local_variable_counter.rb, line 11
        def uses(name)
          @lvars[name][:uses]
        end

[Validate]