Sha256: 88423d53f79480dd4e6061d1b0c914a8479ed9db5b4c44343c763977e42eb235

Contents?: true

Size: 528 Bytes

Versions: 1

Compression:

Stored size: 528 Bytes

Contents

require 'syntax_finder'

# Cound up all of local variable names.

class LVarFinder < SyntaxFinder
  def look node
    if node.respond_to? :locals
      node.locals.each{|lv|
        case lv
        when Symbol
          inc lv
        when Prism::BlockLocalVariableNode
          inc lv.name
        else
          pp [node.type, lv.type, node.locals].inspect
          exit
        end
      }
    end
  end

  def self.print_result
    @@result.sort_by{|lv, v| [-v, lv]}.each{|lv, v|
      puts "#{lv}\t#{v}" 
    }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
syntax_finder-0.1.0 samples/all_lvar_finder.rb