Created
April 14, 2024 05:35
-
-
Save baweaver/1746ec0fdb5054442e22bc4c3920ad87 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
class ShorthandProcCallMacro < Refactor::Rule | |
matches do |node| | |
node in [:block, receiver, | |
[[:arg, arg_name]], [:send, [:lvar, ^arg_name], method_name] | |
] | |
end | |
replace do |_node, match_data| | |
"#{match_data[:receiver].source}(&:#{match_data[:method_name]})" | |
end | |
end | |
# Should translate into something like: | |
class ShorthandProcCallMacro < Refactor::Rule | |
def on_block(node) | |
return false unless node in [:block, receiver, | |
[[:arg, arg_name]], [:send, [:lvar, ^arg_name], method_name] | |
] | |
rewrite("#{receiver.source}(&:#{method_name})") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment