Last active
December 28, 2015 10:19
-
-
Save lazureykis/7485116 to your computer and use it in GitHub Desktop.
do-end vs {}
This file contains hidden or 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
| 2.0.0p0 :036 > puts s1 | |
| 10.times do |n| | |
| puts n | |
| end | |
| => nil | |
| 2.0.0p0 :037 > puts s2 | |
| 10.times { |n| | |
| puts n | |
| } | |
| => nil | |
| 2.0.0p0 :038 > puts d1 = RubyVM::InstructionSequence.compile(s1).disasm | |
| == disasm: <RubyVM::InstructionSequence:<compiled>@<compiled>>========== | |
| == catch table | |
| | catch type: break st: 0002 ed: 0006 sp: 0000 cont: 0006 | |
| |------------------------------------------------------------------------ | |
| 0000 trace 1 ( 1) | |
| 0002 putobject 10 | |
| 0004 send <callinfo!mid:times, argc:0, block:block in <compiled>> | |
| 0006 leave | |
| == disasm: <RubyVM::InstructionSequence:block in <compiled>@<compiled>>= | |
| == catch table | |
| | catch type: redo st: 0000 ed: 0011 sp: 0000 cont: 0000 | |
| | catch type: next st: 0000 ed: 0011 sp: 0000 cont: 0011 | |
| |------------------------------------------------------------------------ | |
| local table (size: 2, argc: 1 [opts: 0, rest: -1, post: 0, block: -1] s3) | |
| [ 2] n<Arg> | |
| 0000 trace 256 ( 1) | |
| 0002 trace 1 ( 2) | |
| 0004 putself | |
| 0005 getlocal_OP__WC__0 2 | |
| 0007 opt_send_simple <callinfo!mid:puts, argc:1, FCALL|ARGS_SKIP> | |
| 0009 trace 512 ( 3) | |
| 0011 leave ( 2) | |
| => nil | |
| 2.0.0p0 :039 > puts d2 = RubyVM::InstructionSequence.compile(s2).disasm | |
| == disasm: <RubyVM::InstructionSequence:<compiled>@<compiled>>========== | |
| == catch table | |
| | catch type: break st: 0002 ed: 0006 sp: 0000 cont: 0006 | |
| |------------------------------------------------------------------------ | |
| 0000 trace 1 ( 1) | |
| 0002 putobject 10 | |
| 0004 send <callinfo!mid:times, argc:0, block:block in <compiled>> | |
| 0006 leave | |
| == disasm: <RubyVM::InstructionSequence:block in <compiled>@<compiled>>= | |
| == catch table | |
| | catch type: redo st: 0000 ed: 0011 sp: 0000 cont: 0000 | |
| | catch type: next st: 0000 ed: 0011 sp: 0000 cont: 0011 | |
| |------------------------------------------------------------------------ | |
| local table (size: 2, argc: 1 [opts: 0, rest: -1, post: 0, block: -1] s3) | |
| [ 2] n<Arg> | |
| 0000 trace 256 ( 1) | |
| 0002 trace 1 ( 2) | |
| 0004 putself | |
| 0005 getlocal_OP__WC__0 2 | |
| 0007 opt_send_simple <callinfo!mid:puts, argc:1, FCALL|ARGS_SKIP> | |
| 0009 trace 512 ( 3) | |
| 0011 leave ( 2) | |
| => nil | |
| 2.0.0p0 :040 > d1 == d2 | |
| => true | |
| 2.0.0p0 :044 > l1 = Ripper.lex(s1) | |
| => [[[1, 0], :on_int, "10"], [[1, 2], :on_period, "."], [[1, 3], :on_ident, "times"], [[1, 8], :on_sp, " "], [[1, 9], :on_kw, "do"], [[1, 11], :on_sp, " "], [[1, 12], :on_op, "|"], [[1, 13], :on_ident, "n"], [[1, 14], :on_op, "|"], [[1, 15], :on_ignored_nl, "\n"], [[2, 0], :on_ident, "puts"], [[2, 4], :on_sp, " "], [[2, 5], :on_ident, "n"], [[2, 6], :on_nl, "\n"], [[3, 0], :on_kw, "end"]] | |
| 2.0.0p0 :045 > l2 = Ripper.lex(s2) | |
| => [[[1, 0], :on_int, "10"], [[1, 2], :on_period, "."], [[1, 3], :on_ident, "times"], [[1, 8], :on_sp, " "], [[1, 9], :on_lbrace, "{"], [[1, 10], :on_sp, " "], [[1, 11], :on_op, "|"], [[1, 12], :on_ident, "n"], [[1, 13], :on_op, "|"], [[1, 14], :on_ignored_nl, "\n"], [[2, 0], :on_ident, "puts"], [[2, 4], :on_sp, " "], [[2, 5], :on_ident, "n"], [[2, 6], :on_nl, "\n"], [[3, 0], :on_rbrace, "}"]] | |
| 2.0.0p0 :046 > l1 == l2 | |
| => false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment