Created
August 31, 2019 05:17
-
-
Save rajasegar/839eb9e70236d205736df4bb4a996e2c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
v:1 | |
parser:2.6.3.0 | |
rails:5.2.3 | |
ruby:2.5.5p157 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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