Sha256: a19ed6bb0a23789c4d8e3f2ae92f1d0e6f04ae136e8d365d12dae7e7ddd43304
Contents?: true
Size: 781 Bytes
Versions: 1
Compression:
Stored size: 781 Bytes
Contents
# frozen_string_literal: true module Preval class Visitors class Loops < Visitor module TrueNode refine Node do def true? is?(:var_ref) && starts_with?(:@kw) && body[0].body == 'true' end end end using TrueNode def on_for(node) sexp = Parser.parse(<<~CODE) #{node.source(1)}.each do |#{node.source(0)}| #{node.source(2)} end CODE node.update(:stmts_add, sexp.body[0].body) end def on_while(node) return unless node.body[0].true? sexp = Parser.parse(<<~CODE) loop do #{node.source(1)} end CODE node.update(:stmts_add, sexp.body[0].body) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
preval-0.3.0 | lib/preval/visitors/loops.rb |