Skip to content

Instantly share code, notes, and snippets.

@rajasegar
Created August 31, 2019 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rajasegar/48f01b007f370a30d1c9020344b90105 to your computer and use it in GitHub Desktop.
Save rajasegar/48f01b007f370a30d1c9020344b90105 to your computer and use it in GitHub Desktop.
A Gist generated by ruby-ast-explorer
v:1
parser:2.6.3.0
rails:5.2.3
ruby:2.5.5p157
# Paste some ruby code here and
# check the generated AST on the right
tips = [
"Click on any AST node with a '+' to expand it",
"Hovering over a node highlights the \
corresponding part in the source code",
]
def print_tips
tips.each { |key, value| print "Tip #{key}: #{value}" }
end
# Your Transform Class should always extend from
# Parser:: TreeRewriter
class Transform < Parser::TreeRewriter
def on_lvasgn(node)
# Reverse the variable names
replace(node.loc.to_hash[:name], node.children[0].to_s.reverse)
end
def on_def(node)
replace(node.loc.to_hash[:name], node.children[0].to_s.reverse)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment