Skip to content

Instantly share code, notes, and snippets.

@hanneskaeufler
Created January 22, 2019 14:40
Show Gist options
  • Save hanneskaeufler/a90add4d07624173db93a142a5312c1a to your computer and use it in GitHub Desktop.
Save hanneskaeufler/a90add4d07624173db93a142a5312c1a to your computer and use it in GitHub Desktop.
Replace `true` with `false`
require "compiler/crystal/syntax/*"
code = <<-CODE
def hello
true
end
CODE
ast = Crystal::Parser.parse(code)
class BooleanTransformer < Crystal::Transformer
def transform(node : Crystal::BoolLiteral)
Crystal::BoolLiteral.new(false)
end
end
puts ast.transform(BooleanTransformer.new)
# => will print:
# def hello
# false
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment