Created
February 6, 2013 03:50
-
-
Save walf443/4720091 to your computer and use it in GitHub Desktop.
nested definitions in ruby?
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 hoge | |
p def fuga | |
p "called fuga" | |
end | |
fuga | |
end | |
hoge | |
fuga | |
# => nil | |
# => "called fuga" | |
# => "called fuga" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$ ruby --dump=insns fuga.rb
== disasm: RubyVM::InstructionSequence:[email protected]=================
0000 trace 1 ( 3)
0002 putspecialobject 1
0004 putspecialobject 2
0006 putobject :hoge
0008 putiseq hoge
0010 send :"core#define_method", 3, nil, 0, ic:0
0016 pop
0017 trace 1 ( 10)
0019 putspecialobject 1
0021 putspecialobject 2
0023 putobject :foo
0025 putiseq foo
0027 send :"core#define_method", 3, nil, 0, ic:1
0033 pop
0034 trace 1 ( 16)
0036 putself
0037 send :hoge, 0, nil, 24, ic:2
0043 pop
0044 trace 1 ( 17)
0046 putself
0047 send :foo, 0, nil, 24, ic:3
0053 pop
0054 trace 1 ( 18)
0056 putself
0057 send :fuga, 0, nil, 24, ic:4
0063 pop
0064 trace 1 ( 19)
0066 putself
0067 send :hoge, 0, nil, 24, ic:5
0073 pop
0074 trace 1 ( 20)
0076 putself
0077 send :fuga, 0, nil, 24, ic:6
0083 leave
== disasm: RubyVM::InstructionSequence:[email protected]===================
0000 trace 8 ( 3)
0002 trace 1 ( 6)
0004 putself
0005 putspecialobject 1 ( 4)
0007 putspecialobject 2
0009 putobject :fuga
0011 putiseq fuga
0013 send :"core#define_method", 3, nil, 0, ic:0
0019 send :p, 1, nil, 8, ic:1 ( 6)
0025 pop
0026 trace 1 ( 7)
0028 putself
0029 send :fuga, 0, nil, 24, ic:2
0035 trace 16 ( 8)
0037 leave ( 7)
== disasm: RubyVM::InstructionSequence:[email protected]===================
0000 trace 8 ( 4)
0002 trace 1 ( 5)
0004 putself
0005 putstring "called fuga in hoge"
0007 send :p, 1, nil, 8, ic:0
0013 trace 16 ( 6)
0015 leave
== disasm: RubyVM::InstructionSequence:[email protected]====================
0000 trace 8 ( 10)
0002 trace 1 ( 13)
0004 putself
0005 putspecialobject 1 ( 11)
0007 putspecialobject 2
0009 putobject :fuga
0011 putiseq fuga
0013 send :"core#define_method", 3, nil, 0, ic:0
0019 send :p, 1, nil, 8, ic:1 ( 13)
0025 trace 16 ( 14)
0027 leave ( 11)
== disasm: RubyVM::InstructionSequence:[email protected]===================
0000 trace 8 ( 11)
0002 trace 1 ( 12)
0004 putself
0005 putstring "called fuga in foo"
0007 send :p, 1, nil, 8, ic:0
0013 trace 16 ( 13)
0015 leave ( 12)