-
-
Save anonymous/3977148 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
code = <<END | |
class Post | |
class << self | |
end | |
end | |
END | |
puts RubyVM::InstructionSequence.compile(code).disasm | |
### | |
sent-hil:ruby/ (trunk✗) $ ruby example.rb [19:10:20] | |
== disasm: <RubyVM::InstructionSequence:<compiled>@<compiled>>========== | |
0000 trace 1 ( 1) | |
0002 putspecialobject 3 | |
0004 putnil | |
0005 defineclass :Post, <class:Post>, 3 | |
0009 leave | |
== disasm: <RubyVM::InstructionSequence:<class:Post>@<compiled>>======== | |
0000 trace 2 ( 1) | |
0002 trace 1 ( 2) | |
0004 putself | |
0005 putnil | |
0006 defineclass :singletonclass, singletonclass, 1 | |
0010 trace 4 ( 4) | |
0012 leave ( 2) | |
== disasm: <RubyVM::InstructionSequence:singletonclass@<compiled>>====== | |
0000 trace 2 ( 2) | |
0002 putnil ( 3) | |
0003 trace 4 | |
0005 leave |
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
require 'ripper' | |
require 'pp' | |
code = <<STR | |
class Post | |
class << self | |
end | |
end | |
STR | |
puts code | |
pp Ripper.lex(code) | |
sent-hil:ruby/ (trunk✗) $ ruby example.rb [19:11:52] | |
class Post | |
class << self | |
end | |
end | |
[[[1, 0], :on_kw, "class"], | |
[[1, 5], :on_sp, " "], | |
[[1, 6], :on_const, "Post"], | |
[[1, 10], :on_nl, "\n"], | |
[[2, 0], :on_sp, " "], | |
[[2, 2], :on_kw, "class"], | |
[[2, 7], :on_sp, " "], | |
[[2, 8], :on_op, "<<"], | |
[[2, 10], :on_sp, " "], | |
[[2, 11], :on_kw, "self"], | |
[[2, 15], :on_nl, "\n"], | |
[[3, 0], :on_sp, " "], | |
[[3, 2], :on_kw, "end"], | |
[[3, 5], :on_nl, "\n"], | |
[[4, 0], :on_kw, "end"], | |
[[4, 3], :on_nl, "\n"]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment