polishing ruby by ryan davis

Dear Lazyweb: Proc disassembly in 1.9?

Published 2008-06-23 @ 13:25

Tagged ruby

Clue me? How do I disassemble a proc in 1.9?

  >> p = proc { |n| n + 2 } 
  => #<Proc:0x3be994@(irb):1>
  >> VM::InstructionSequence.disassemble p
  >> class Temp1; end
  >> Temp1.send :define_method, :m, p
  => #<Proc:0x3be9e4@(irb):1 (lambda)>
  >> VM::InstructionSequence.disassemble(Temp1.instance_method :m)
  => nil
  >> VM::InstructionSequence.disassemble(Temp1.new.method(:m))
  => nil
  >> class Temp2; def m; 1 + 2; end; end
  => nil
  >> puts VM::InstructionSequence.disassemble(Temp2.instance_method(:m))
  == disasm: <ISeq:x@(irb)>===============================================
  0000 putobject        1                                               (  12)
  0002 putobject        2
  0004 opt_plus         
  0005 leave            
  => nil