Sha256: 4948ab474da349185ef3155310d0c5433b064dcc45b36654e4fe14f8fd111651
Contents?: true
Size: 1.17 KB
Versions: 3
Compression:
Stored size: 1.17 KB
Contents
require 'set' require 'reek/code_context' module Reek module ParameterSet def names return @names if @names return (@names = []) if empty? arg = slice(1) case slice(0) when :masgn @names = arg[1..-1].map {|lasgn| Name.new(lasgn[1]) } when :lasgn, :iasgn @names = [Name.new(arg)] end end def include?(name) names.include?(name) end end class VariableContainer < CodeContext def initialize(outer, exp) super @local_variables = Set.new end def record_local_variable(sym) @local_variables << Name.new(sym) end end class BlockContext < VariableContainer def initialize(outer, exp) super @name = Name.new('block') @parameters = exp[2] || [] @parameters.extend(ParameterSet) end def inside_a_block? true end def has_parameter(name) @parameters.include?(name) or @outer.has_parameter(name) end def nested_block? @outer.inside_a_block? end def outer_name "#{@outer.outer_name}#{@name}/" end def variable_names @parameters.names + @local_variables.to_a end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
reek-1.2.5 | lib/reek/block_context.rb |
reek-1.2.4 | lib/reek/block_context.rb |
reek-1.2.3 | lib/reek/block_context.rb |