Skip to content

Instantly share code, notes, and snippets.

@benolee
Created October 11, 2012 15:14
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 benolee/45ca43e003e6d8e9a8fa to your computer and use it in GitHub Desktop.
Save benolee/45ca43e003e6d8e9a8fa to your computer and use it in GitHub Desktop.
using RubyVM::InstructionSequence.disassemble for a DSL
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