-
-
Save benolee/45ca43e003e6d8e9a8fa to your computer and use it in GitHub Desktop.
using RubyVM::InstructionSequence.disassemble for a DSL
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
def wat &block | |
method, receiver, *args = RubyVM::InstructionSequence.disassemble(block).scan(/send\s+:(\w+)/).reverse.flatten | |
{ receiver: receiver, method: method, args: args } | |
end | |
wat { (puts Kernel test (hello world)) } | |
#=> {:receiver=>"Kernel", :method=>"puts", :args=>["test", "hello", "world"]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment